1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
class APrivate { public: int i = 3; }; class A { public: A() : d(new APrivate()) {} A(const A &other) : d(new APrivate(*other.d)) {} ~A() { delete d; } private: APrivate *const d; }; void test() { A a; A a2; }