[C++-sig] setting up held smart pointer for pure virtual base class

David Abrahams dave at boost-consulting.com
Thu Oct 13 16:31:38 CEST 2005


Scott McKay <skottmckay at gmail.com> writes:

> I have a pure virtual base class (so no_init is set).

There's no such thing.  I assume you mean an abstract base class?

> The base class is held by a smart pointer.

You mean in its Python wrapper class?

> I want to implement that class in python.

Do you mean you want to derive from that class in python?

> I know that calling the __init__ function of the base class sets up the
> smart pointer that is held by boost::python.

Yes.

> Is there some other way to set that up given the base class has no __init__
> function? 

Nope.

> If it isn't setup I get an ArgumentError as the types don't match.
>
> If I make the base class virtual (by providing dummy implementations for
> what were the pure virtual functions) 

That's not a virtual base class.  A virtual base class is:


       // This-----------V
       class A : virtual B
       {
          ...
       };

> and call the __init__ everything works.

You need to expose an __init__ so derived classes can initialize the
base; there are no two ways about it.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




More information about the Cplusplus-sig mailing list