一个类如何防止被拷贝

    Effective C++:条款06

  若不想使用编译器自动生成的函数,就该明确拒绝 .

老式写法

class noncopyable  
{  
protected:  
    noncopyable() {}  
    ~noncopyable() {}  
private:  
    noncopyable( const noncopyable& );  
    noncopyable& operator=( const noncopyable& );  
};  


C++11写法:

class noncopyable  
{  
protected:  
    //constexpr noncopyable() = default;  
   // ~noncopyable() = default;  
    noncopyable( const noncopyable& ) = delete;  
    noncopyable& operator=( const noncopyable& ) = delete;  
};  


转载:

http://blog.csdn.net/flyfish1986/article/details/43305363


你可能感兴趣的:(C++基础)