[C++-sig] type traits
Piotr Jaroszyński
p.jaroszynski at gmail.com
Sat Jun 30 19:18:01 CEST 2007
Hello,
I thought (and saw) that boost.python is using type traits to figure out the
real type of polymorphic pointers/references and hence I am really surprised
that with the following code it doesn't happen:
#include <boost/python.hpp>
namespace bp = boost::python;
struct Base
{
};
struct Derived :
Base
{
};
const boost::shared_ptr<Base>
get_derived()
{
static boost::shared_ptr<Base> foo(boost::shared_ptr<Derived>(new
Derived()));
return foo;
}
BOOST_PYTHON_MODULE(type_magic)
{
bp::class_<Base>("Base", bp::no_init);
bp::register_ptr_to_python<boost::shared_ptr<Base> >();
bp::class_<Derived, bp::bases<Base> >("Derived", bp::no_init);
bp::def("get_derived", &get_derived);
}
in python get_derived gives me:
<type_magic.Base object at 0x2adb9e8ba848>
For the "saw" part, I have working code, which does exactly what I expected
(getting a Derived object in python) and I can't really find a difference
between it and this basic testcase, but I am probably just missing something.
Any clues what that could be?
--
Best Regards,
Piotr Jaroszyński
More information about the Cplusplus-sig
mailing list