All pastes #504749 Raw Edit

Someone

public text v1 · immutable
·published 2007-05-23 07:43 UTC
rendered paste body
#include <iostream>
#include <boost/shared_ptr.hpp>


template <class T> class nondeletable
{
  friend class boost::shared_ptr<T>;
  template <class X> class deleter;
  friend class deleter<T>;

public:
  typedef boost::shared_ptr<T> Ptr;

  static Ptr create()
  {
    Ptr px(new T, deleter<T>());
    return px;
  }

protected:
  nondeletable() {}
  ~nondeletable() {}

private:
  nondeletable(const nondeletable&);
  const nondeletable& operator=(const nondeletable&);

  template <class X> class deleter
  {
  public:
    void operator()(X * p) { delete p; }
  };


};

class FooFactory
{

public:
  static Foo::Ptr create()
  {
    return Foo::create();
  }

};


class Foo : public nondeletable<Foo> // musita periyttää
{
  friend class nondeletable<Foo>; // 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;
}