To prohibit copy construction and copy assignment, I’ve seen the boost noncopyable class and in the Google style guide the DISALLOW_COPY_AND_ASSIGN macro. Is there any reason to prefer one of the techniques over the other, or any subtle differences one should be aware of?
To prohibit copy construction and copy assignment, I’ve seen the boost noncopyable class and
Share
I prefer boost noncopyable over the macro because it’s not a macro and it is easier (IMO) to use.
In real code, i’m using neither of them and write the two declarations needed myself.
A subtle difference you might be interested in, though, is that using that macro or your own declarations will not give a compiler error when the class itself tries to copy the object (but rather fail to link later on).
noncopyablehowever will also signal a compiler error in this case, because it’s the base-class that has the functions declared private, not the class itself.