To reject the functions automatically provided by the compiler, the corresponding member functions can be declared as private and not implemented.
If the member function or the friend function calls these functions, an error is reported during the connection.
It is possible to move a connection error to the compilation phase. Set a base classs specifically designed to prevent copying actions:
Class uncopyable {
Protected: // allows derived Object Construction and Analysis
Uncopyable (){}
~ Uncopyable (){}
PRIVATE: // block copying
Uncopyble (const uncopyable &);
Uncopyable & operator = (const uncopyable &);
};
Class homeforsale: Private uncopyable {// class does not declare the copy constructor and the copy assignment operator
};
As long as anyone tries to copy the homeforsale object, the compiler will try to generate a copy constructor and a copy assignment operator. The Compiler version of these functions will try to call the corresponding brother of their base class, those calls will be rejected by the compiler because the copy function of the base class is private.