[C++-sig] non const std::string* as argument
Max Ivanov
ivanov.maxim at gmail.com
Thu Aug 21 11:30:23 CEST 2008
Hi all!
How to export to python class members like "bool
SerializeToString(string* output) const"? In python strings are
immutables, so there is no way to export this method directly. So I
tried to write a wrapper:
std::string& wrap_SerializeToString(const gp::Message& msg) {
std::string tmp;
msg.SerializeToString(&tmp);
return tmp;
};
and then how I use it. Message class is base class for Link which I
try to export to python, but Link never overrides SerializeToString.
bp::class_<gp::Message, boost::noncopyable>("Message", bp::no_init)
.def("SerializeToString", wrap_SerializeToString,
bp::return_value_policy<bp::copy_const_reference())
gcc errors are following:
bindings.cpp: In function 'std::string& wrap_SerializeToString(const
google::protobuf::Message&)':
bindings.cpp:21: warning: reference to local variable 'tmp' returned
bindings.cpp: In function 'void init_module__spidermsg()':
bindings.cpp:46: error: a call to a constructor cannot appear in a
constant-expression
bindings.cpp:46: error: template argument 1 is invalid
More information about the Cplusplus-sig
mailing list