[C++-sig] inheritance problem when using constructor

Luca Sbardella luca.sbardella at gmail.com
Thu May 10 18:32:34 CEST 2007


Hi all,
I have a problem regarding inheritance/polymorphism which I cannot get to
the bottom of it.
In C++ I have a pure virtual class, lets called it an interface, called
"its" and an implementation of it called "ts".
I exposed the two to python using the "wrapper.hpp" module.

struct ts_wrapper : its,  wrapper<its>
{
int    get_numdates() const {....}
}

typedef boost::shared_ptr<its> ITS;
register_ptr_to_python<ITS>();

class_<ts_wrapper, boost::noncopyable>("itimeserie", "Time serie interface")
        .def("get_numdates",
pure_virtual(&its::get_numdates));

class_<ts, bases<ts_wrapper>>("timeserie", "An implementation of
itimeserie", init<const list&,const dict&>());

def("ts_create",&timeserieFactory::Create,"Get a time serie");


timeserieFactory returns a smart pointer to the interface "its", ITS.

Now, in Python, when I create an instance of "timeserie" using the
"ts_create" everything works fine, i.e. I can call the method "get_numdates"
without any problem. However when I create an instance of "timeserie" using
the constructor, the object is constructed correctly but when I call
"get_numdates" this is what python think about it

Boost.Python.ArgumentError: Python argument types in
    itimeserie.get_numdates(timeserie)
did not match C++ signature:
    get_numdates(class ts_wrapper {lvalue})
    get_numdates(class its {lvalue})

somehow when I use the constructor, the instance is not recognized as
derived from the interface.
Luca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070510/ad92c7a4/attachment.htm>


More information about the Cplusplus-sig mailing list