summaryrefslogtreecommitdiff
path: root/inputmethods/dasher/NoClones.h
Unidiff
Diffstat (limited to 'inputmethods/dasher/NoClones.h') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/dasher/NoClones.h39
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 @@
1#ifndef __NoClones_h__
2#define __NoClones_h__
3
4/* Explanation of NoClones {{{
5
6C++ defines default copy constructors and assignment operators, which clone
7every member of a class. Stroustrup describes this behaviour as the result of
8"historical accident". For many non-trivial classes, especially those
9containing pointers, this default behaviour is too naive. In fact it often leads
10to heap corruption.
11
12Sometimes it does not make any sense to copy an instance of a class. For
13example if it contains a unique file handle, or other lock on a system resource.
14Sometimes it is too much effort to write reliable replacement copy operations[1].
15In either case a private copy constructor and a private assignment operator
16prevent accidental copying. [2]
17
18Deriving a class from this class has the same preventative effect. It is also a
19bit neater and means that all the above explanation is centralised here.
20
21IAM 09/2002
22
23[1] An example of how it is very easy to make mistakes:
24http://www.mistybeach.com/articles/WhyIDontLikeCPlusPlusForLargeProjects.html
25If 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
27
28}}} */
29
30class NoClones
31{
32protected: // Default constructor doesn't need to be public, but can't be private.
33 NoClones() {}; // Lots of compiler complaints without default constructor.
34private:
35 NoClones(const NoClones&);
36 NoClones& operator=(const NoClones&);
37};
38
39#endif /* #ifndef __NoClones_h__ */