3-muduo-base-noncopyable
class noncopyable
{
public:
noncopyable(const noncopyable&) = delete;
void operator=(const noncopyable&) = delete;
protected:
noncopyable() = default;
~noncopyable() = default;
};
将拷贝构造函数和=操作符都=delete
-
构造函数和析构函数都声明为
protected。原因见copyable处的解析。 -
C++11中,当我们定义一个类的成员函数时,如果后面使用"=delete"去修饰,那么就表示这个函数被定义为deleted,也就意味着这个成员函数不能再被调用,否则就会出错。
-
=default关键字:默认函数需要用于特殊的成员函数(默认构造函数,复制构造函数,析构函数等),或者没有默认参数。
=default和=delete:

浙公网安备 33010602011771号