0

How to converter std::string* in boost.python?I have to handle some data of c++ in python.The data may be big.So I return a pointer to python. But there are some errors.

c++

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

class A {
public:
    A() {
        data="342342fgsf";
        ss=&data;
    }
    std::string *ss;
    std::string data;
};

BOOST_PYTHON_MODULE(ctopy)
{
    using namespace boost::python;
    class_<A> ("A",init<>())
        .add_property(ss,&A::ss)
    ;
}

python

import ctopy
t1=ctopy.A()
print t1.ss     #error.TypeError:No to_python (by-value) converter found for c++ type:std::string*
simon
  • 569
  • 9
  • 20
  • see http://www.boost.org/doc/libs/1_42_0/libs/python/doc/v2/faq.html#custom_string - maybe this helps? – Jakob S. Dec 21 '12 at 10:20
  • Have a look at this, appears relevant. [link](http://stackoverflow.com/questions/2541446/exposing-a-pointer-in-boost-python?rq=1) – Jimmy Thompson Dec 21 '12 at 12:27

1 Answers1

0

You can't just pass pointer. Use pointer_wrapper: http://www.boost.org/doc/libs/1_53_0/libs/python/doc/v2/ptr.html

Tsar Ioann
  • 444
  • 4
  • 9