Declare an assignment statement private:
class A { private: void operator=(const A&); ... };
but they donβt provide an implementation - you will receive a compilation error or link time error message if you try to assign A.
I prefer to use a macro for this. It also prevents copying, while also making the copy constructor private:
#define CANNOT_COPY( class ) \ private: \ class(const class&); \ void operator=(const class &) \
Then I can say things like:
class A { CANNOT_COPY( A ); ... };
which is easy to read and easy to find.
anon
source share