美文网首页
条款06:若不想使用编译器自动生成的函数,就该明确拒绝

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

作者: robotai | 来源:发表于2020-09-28 22:39 被阅读0次

1、不想使用copy 函数的方法,是将copy函数放到私有里。

class A {

...

private:

A(const A &);

A & operator=(const A &);

};

2、使用可以阻止copy行为的基类,私有继承

class uncopy{

..

private:

uncopy(const uncopy&);

uncopy & operator=(const uncopy&);

};

class other: private A {...};   //私有继承

相关文章

网友评论

      本文标题:条款06:若不想使用编译器自动生成的函数,就该明确拒绝

      本文链接:https://www.haomeiwen.com/subject/hzmjuktx.html