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 {...}; //私有继承
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
网友评论