[C++-sig] Re: Shared pointers and python subclasses

David Abrahams dave at boost-consulting.com
Fri Sep 10 18:16:30 CEST 2004


Itamar Shtull-Trauring <itamar at itamarst.org> writes:

> I have a structure somewhat like this (I simplified to explain):
>
> typedef boost::shared_ptr<RecordHandler> RecordHandlerPtr;
> class_<RecordHandler, RecordHandlerWrap>("RecordHandler");
> class_<CacheRecordRetriever>("CacheRecordRetriever",init<RecordHandlerPtr>());
>
> Now, if I subclass RecordHandler in python, I can't pass an instance of
> the subclass to CacheRecordRetriever's constructor in my Python code, it
> raises a RuntimeErorr claiming it's the wrong type. How do I solve this?

The one explanation I can think of is that you've defined an __init__
function in your subclass that doesn't call RecordHandler.__init__.
That is what would create the contained C++ RecordHandler object, and
without that you can't convert it to a RecordHandlerPtr.

If that's not the case please post a small, reproducible example.  One
C++ file and one Python file.  This is supposed to work.


-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com




More information about the Cplusplus-sig mailing list