C++ Lecture 7 - C+ Lecture 7

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ Lecture 7 http://www.cs.mun.ca/~gstarkes/3710/c++/lecture7.html 1 of 2 4/13/2009 5:28 PM C++ Lecture 7 [Previous Lecture] [Lecture Index] [Next Lecture] Defensive Class Design Common problems caused by mis-use of classes: passing class by value (copy is created with shared contents, then destroyed) assigning one instance from another (old contents overwritten, new contents shared) Solution: design classes to deal with or prevent misuse define a copy constructor, if necessary/possible, that creates a completely independent copy define operator= method, if necessary/possible, that releases old resources creates a completely independent copy Also, handle assignment to self. if not possible, create a private copy constructor/ operator= which print an error if called Note: If your destructor does anything, you probably need a copy constructor and assignment operator. Intro to Templates used to avoid re-writing functions/classes with only minor vari ations ( e.g.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/24/2009 for the course PROGRAMMIN C++ Progra taught by Professor Showman during the Spring '09 term at Zagazig University.

Page1 / 3

C++ Lecture 7 - C+ Lecture 7

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online