[C++-sig] Calling func that takes intrusive_ptr<Base> with intrusive_ptr<Derived>...

Alex Mohr amohr at pixar.com
Tue Dec 20 01:15:29 CET 2005


Hmm.. I was expecting this to work.  Any ideas as to why it doesn't?

Thanks,

Alex


#include <boost/python.hpp>
#include <boost/smart_ptr.hpp>
#include <string>

using namespace boost::python;
using boost::intrusive_ptr;
using std::string;

class Base { public: virtual ~Base() {} };
class Derived : public Base { public: virtual ~Derived() {} };

void intrusive_ptr_add_ref(Base *base) {}
void intrusive_ptr_add_ref(Base *base) {}

intrusive_ptr<Derived> makeDerived() {
     return intrusive_ptr<Derived>(new Derived());
}

string takesBasePtr(intrusive_ptr<Base> const &base) {
     return "takesBasePtr";
}

BOOST_PYTHON_MODULE(foo) {
     class_<Base, intrusive_ptr<Base> >("Base", no_init);
     class_<Derived, intrusive_ptr<Derived>, bases<Base> >
         ("Derived", no_init)
         .def("__init__", make_constructor(makeDerived))
         .def("takesBasePtr", takesBasePtr)
     ;
}

==================================================

 >>> from foo import *
 >>> d = Derived()
 >>> d.takesBasePtr()
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
Boost.Python.ArgumentError: Python argument types in
     Derived.takesBasePtr(Derived)
did not match C++ signature:
     takesBasePtr(boost::intrusive_ptr<Base>)




More information about the Cplusplus-sig mailing list