#include #include template class nondeletable { friend class boost::shared_ptr; template class deleter; friend class deleter; public: typedef boost::shared_ptr Ptr; static Ptr create() { Ptr px(new T, deleter()); return px; } protected: nondeletable() {} ~nondeletable() {} private: nondeletable(const nondeletable&); const nondeletable& operator=(const nondeletable&); template class deleter { public: void operator()(X * p) { delete p; } }; }; class FooFactory { public: static Foo::Ptr create() { return Foo::create(); } }; class Foo : public nondeletable // musita periyttää { friend class nondeletable; // muista tämä protected: // ja tämä Foo() { std::cerr << "Foo created" << std::endl; } ~Foo() { std::cerr << "Foo destroyed" << std::endl; } }; int main (void) { // Foo foo3; Foo::Ptr foo = FooFactory::create(); Foo::Ptr foo2 = foo; //delete foo.get(); std::cerr << "ending" << std::endl; return 0; }