tagging release
[dasher.git] / Src / Common / NoClones.h
blob6490c58164c3b4446a7f679e1160334a61eb4db8
1 #ifndef __NoClones_h__
2 #define __NoClones_h__
4 /* Explanation of NoClones {{{
6 C++ defines default copy constructors and assignment operators, which clone
7 every member of a class. Stroustrup describes this behaviour as the result of
8 "historical accident". For many non-trivial classes, especially those
9 containing pointers, this default behaviour is too naive. In fact it often leads
10 to heap corruption.
12 Sometimes it does not make any sense to copy an instance of a class. For
13 example if it contains a unique file handle, or other lock on a system resource.
14 Sometimes it is too much effort to write reliable replacement copy operations[1].
15 In either case a private copy constructor and a private assignment operator
16 prevent accidental copying. [2]
18 Deriving a class from this class has the same preventative effect. It is also a
19 bit neater and means that all the above explanation is centralised here.
21 IAM 09/2002
23 [1] An example of how it is very easy to make mistakes:
24 http://www.mistybeach.com/articles/WhyIDontLikeCPlusPlusForLargeProjects.html
25 If we don't need a copy feature it really isn't worth the hassle.
26 [2] The C++ Programming Language. Stroustrup. 3rd edition. Section 10.4.6.3
28 }}} */
30 class NoClones {
31 protected: // Default constructor doesn't need to be public, but can't be private.
32 NoClones() {
33 }; // Lots of compiler complaints without default constructor.
34 private:
35 NoClones(const NoClones &);
36 NoClones & operator=(const NoClones &);
39 #endif /* #ifndef __NoClones_h__ */