Boost logo

Boost :

From: John Hunter (jdhunter_at_[hidden])
Date: 2001-08-17 13:11:25

I have some classes that I want to use polymorphically like this:

class Base;
typedef boost::shared_ptr<Base> SmartPtrBase;

class Base {
  virtual ~Base() {};
  virtual void sayit() const=0;

class Foo : public Base {
  void sayit() const { cout << "Foo" << endl; }

class Bar {
  Bar( SmartPtrBase p) : pB(p) {}
  void says() const { pB->sayit(); }
  SmartPtrBase pB;

The problem I am having is if I construct a Foo in python, I don't
know how to pass it to Bar in the constructor. Is the only way to
make Base declare a clone method that returns a SmartPtrBase, eg

  virtual SmartPtrBase clone() =0;

and then in python do,

f = Foo()

bar = Bar( f.clone() )

Or is there a less intrusive (ie, one where I don't have to write the
clone methods for all derived classes) or better to take an object
created in python and pass it to a class that is expecting a smart
pointer to that object?

John Hunter

Boost list run by bdawes at, gregod at, cpdaniel at, john at