6. Explicitly disallow the use of compiler generated functions you do not want

来源:互联网 发布:孕妇枕 知乎 编辑:程序博客网 时间:2024/05/16 15:41

declaring member functions private and deliberately not implementing them

class HomeForSale {public:    ...private:    ...    HomeForSale(const HomeForSale&);    HomeForSale& operator=(const HomeForSale&);};  

declaring the copy constructor and copy assignment operator private not in HomeForSale itself, but in a base class

class Uncopyable {protected:    Uncopyable() {}    ~Uncopyable() {}private:    Uncopyable(const Uncopyable&);    Uncopyable& operator=(const Uncopyable&);};class HomeForSale: private Uncopyable {    ...};

Uncopyable is not designed to allow the manipulation of derived class objects via base class interfaces. As a result, they do not need virtual destructor.

阅读全文
0 0
原创粉丝点击