Lecture overview -- Keyboard shortcut: 'u'  Previous page: Inheritance: Constructors and destructors  -- Keyboard shortcut: 'p'  Next page: Member access control: private, public and protected -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 4 - Page 3 : 24
Notes about C++
Abstraction Mechanisms, Part 2
Inheritance: Copying and slicing

'Real object-oriented programming' relies on reference semantics (use of pointers or C++ references to objects) rather than value semantics (copying of objects)

  • The C++ Programming Language: Page 307
 

  • In the example programs: The class B is derived from class A

    • We copy an instance of B to a variable of type A

    • No pointer types or reference types are involved

    • The B part of the object is lost

    • We say that it is sliced

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/slicing/slice-1.ccIllustration of object slicing.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/slicing/slice-1-outputProgram output.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/slicing/slice-2.ccDoes this variant change the game?.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/slicing/slice-2-outputProgram output.


Go to exerciseSlicing an object during parameter passing.