标签:otto margin lap 构造函数 通过 code 定义函数 ase rtu
class Empty {};
//事实上等价于
class Empty {
public:
Empty() { ... } //default constructor
Empty(const Empty &rhs) { ... } //copy constructor
~Empty() { ... } //destructor
Empty& operator=(const Empty &rhs) { ... } //copy assignment
};假设你不声明 copy 构造函数或者 copy assignment 操作符,编译器将为你产生一份;假设你声明他们。你的类相同支持 copying。
class A {
public:
private:
A(const A &rhs); //仅仅有声明
A& operator=(const A &rhs);
};class Uncopyable {
public:
Uncopyable() {}
~Uncopyable() {}
private:
Uncopyable(const Uncopyable&);
Uncopyable& operator=(const Uncopyable&);
};
class B : private Uncopyable {
};
另一点须要注意的是,继承用 private 而不是 public。这样能够阻止public继承时。下列的代码:(内存泄漏,由于通过基类的指针删除派生类对象,基类必须是 virtual 虚函数,否则内存泄漏)Uncopyable *p = new B(); ... delete p;
标签:otto margin lap 构造函数 通过 code 定义函数 ase rtu
原文地址:http://www.cnblogs.com/jzdwajue/p/6758166.html