We all know from previous posts that compiler will generate constructors, destructors and assignment operator for you. What if you don’t need or you want to prevent compiler to generate them for you? The ways is to declare the corresponding member functions private and give no implementations. Here we will have a uncopyable class to demonstrate how to implement this.
Uncopyable& operator=(const Uncopyable&);
If you do
Uncopyable a, b;
a = b;
The compiler will complain about assignment operator is private. and if you call it in a member or a friend function, the linker will complain about can’t find implementation of this function.