Boost logo

Boost Users :

Subject: [Boost-users] Boost.python - How to export shared_ptr<vector<shared_ptr<string> > >?
From: blp330 (blp330_at_[hidden])
Date: 2009-03-07 11:19:42


I have a function that returns type
boost::shared_ptr<std::vector<boost::shared_ptr<std::string> > >,
I have registered that:

// boost::shared_ptr<std::string> -> PyString Converter.
struct StringPointerToPyString {
    static ::PyObject* convert( ::boost::shared_ptr<::std::string> const&
p_str ){
        return ::PyString_FromStringAndSize( p_str->data(), p_str->size() );

bp::class_< std::vector<StringPtr> > ("vector_StringPtr")
    .def (bp::vector_indexing_suite< std::vector<StringPtr> >());
bp::register_ptr_to_python< boost::shared_ptr< std::vector<StringPtr> > >();

It works fine but when I try to access the returned vector, I got error:

>>> v = my_function()
>>> v[0]
TypeError: No Python class registered for C++ class class
boost::shared_ptr<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >

I tried to add

bp::register_ptr_to_python< boost::shared_ptr< std::string > >();

But still not work.

How can I make it work?

Thanks you very much.

View this message in context:
Sent from the Boost - Users mailing list archive at

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at