Cpp Coding Standards/CLSINIT/ObvCopy

From Apache OpenOffice Wiki
< Cpp Coding Standards‎ | CLSINIT
Revision as of 13:59, 1 February 2007 by Np (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Obvious Copyability

Summary

When designing a class, make clear the intention regarding copies and assignment. There are four possibilities:

  1. The default copying behaviour as provided by the compiler is correct. In this case it may be useful to provide a comment that explicitely states this.
  2. The class shall be copied, but the default behaviour is not correct. This is the case, if the class has members (like pointers that administrate heap memory) that do not copy correctly with the default behaviour. In this case implement copy constructor and operator=().
  3. The class is not intended to be copied. Make this explicit by either deriving from boost::noncopyable or declaring (but not implementing) copy constructor and operator=() private.
  4. If the class is an abstract base class, it is often not necessary to decide, if derived classes should be copyable. Slicing is not possible, because these classes cannot be instantiated. So in this case nothing has to be done.
Personal tools