将拷贝构造函数和等于号重定义声明为私有函数即可编写一个不可拷贝类,其他类只需继承这个类就能实现不可拷贝。
不可拷贝意味着只能用指针或引用传参,节约资源。
class base
{
private:
base(const base&);
const base& operator=(const base&);
protected:
base() { }
~base() { }
};
将拷贝构造函数和等于号重定义声明为私有函数即可编写一个不可拷贝类,其他类只需继承这个类就能实现不可拷贝。
不可拷贝意味着只能用指针或引用传参,节约资源。
class base
{
private:
base(const base&);
const base& operator=(const base&);
protected:
base() { }
~base() { }
};