Believe me, you do not want to do this.
Take a look at boost::shared_ptr : it allows you to deal with pointers in an elegant way without worrying too much about deleting them.
class Foo { public: boost::shared_ptr<int> p; }; Foo *f1 = new Foo(); Foo *f2 = new Foo(); f1->p.reset(new int(1)); f2->p = f1->p; delete f2;
If you do not want to use boost , some compilers already provide std::tr1::shared_ptr , which has similar semantics.
source share