First, in order to dismiss the function provided automatically by the compiler, the corresponding member function can be declared private and not implemented . (the compiler will help you if you just don't implement it yourself)
Such as:
class a{ public : A ( const string & name): M_name (name) {} private : // rejects copy and assignment, declares private, and declares only that it does not implement A (const a&); A & operator = (const a&< Span style= "color: #000000;" >); private : string M_name;};
Second, for the class that denies the assignment copy, you can also inherit a uncopyable base class .
classuncopyable{ Public: Uncopyable () {}~uncopyable () {}Private: Uncopyable (Constuncopyable&); Uncopyable&operator=(Constuncopyable&);};
classA: PublicUncopyable//Inherit uncopyable not necessarily public!{ Public: A (Const string&name): M_name (name) {}Private: stringm_name;};
Effective C + + learning NOTE Clause 06: If you do not want to use the compiler automatically generated functions, you should explicitly deny