Lecture overview -- Keyboard shortcut: 'u'  Previous page: Example of copying objects: Programmed copying -- Keyboard shortcut: 'p'  Next page: Classes and Conversion -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 3 - Page 17 : 36
Notes about C++
Abstraction Mechanisms, Part 1
Preventing object copying

If you do not define a copy constructor and an assignment operator yourself, the compiler provides them for you

This is not convenient if you explicitly want to prevent object copying

Compiler enforced prevention

  • Effective C++, Third edition: Item 6
 

  • Solution

    • Declare the copy constructor and the assignment operator as private

    • Do not define these

    • Leads to linker errors in case the copy constructor or the assignment is actually used...

    • See Effective C++, Third edition item 6

This is a trick!