1.将拷贝构造函数和赋值运算符声明为私有,并不予实现
class Uncopyable { private: Uncopyable(const Uncopyable &); // 阻止copying Uncopyable &operator=(const Uncopyable &); };
2.使用delete
class Uncopyable { Uncopyable(const Uncopyable &) =delete; // 阻止copying Uncopyable &operator=(const Uncopyable &)=delete; };