author | mickeyl <mickeyl> | 2003-09-27 11:29:26 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-09-27 11:29:26 (UTC) |
commit | 651b6c612db4e809c506973996f2580c4158ac3a (patch) (side-by-side diff) | |
tree | 8c8edc86e4b206dd4542a6b556ad1a319d6698ab /inputmethods/dasher/NoClones.h | |
parent | d1a11b45e805fe7771ea05944757d767c3c4c8ea (diff) | |
download | opie-651b6c612db4e809c506973996f2580c4158ac3a.zip opie-651b6c612db4e809c506973996f2580c4158ac3a.tar.gz opie-651b6c612db4e809c506973996f2580c4158ac3a.tar.bz2 |
merge dasher which has been introduced in BRANCH first (wtf?) into HEAD
Diffstat (limited to 'inputmethods/dasher/NoClones.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/dasher/NoClones.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/inputmethods/dasher/NoClones.h b/inputmethods/dasher/NoClones.h new file mode 100644 index 0000000..11cdabb --- a/dev/null +++ b/inputmethods/dasher/NoClones.h @@ -0,0 +1,39 @@ +#ifndef __NoClones_h__ +#define __NoClones_h__ + +/* Explanation of NoClones {{{ + +C++ defines default copy constructors and assignment operators, which clone +every member of a class. Stroustrup describes this behaviour as the result of +"historical accident". For many non-trivial classes, especially those +containing pointers, this default behaviour is too naive. In fact it often leads +to heap corruption. + +Sometimes it does not make any sense to copy an instance of a class. For +example if it contains a unique file handle, or other lock on a system resource. +Sometimes it is too much effort to write reliable replacement copy operations[1]. +In either case a private copy constructor and a private assignment operator +prevent accidental copying. [2] + +Deriving a class from this class has the same preventative effect. It is also a +bit neater and means that all the above explanation is centralised here. + +IAM 09/2002 + +[1] An example of how it is very easy to make mistakes: +http://www.mistybeach.com/articles/WhyIDontLikeCPlusPlusForLargeProjects.html +If we don't need a copy feature it really isn't worth the hassle. +[2] The C++ Programming Language. Stroustrup. 3rd edition. Section 10.4.6.3 + +}}} */ + +class NoClones +{ +protected: // Default constructor doesn't need to be public, but can't be private. + NoClones() {}; // Lots of compiler complaints without default constructor. +private: + NoClones(const NoClones&); + NoClones& operator=(const NoClones&); +}; + +#endif /* #ifndef __NoClones_h__ */ |