[C++-sig] Boost.Python: wrapping a method returning const std::string &

Bilokon, Paul paul.bilokon at lehman.com
Thu Aug 14 17:51:58 CEST 2008


Hi Olaf,

Thanks a lot. This was certainly an informative error message.

As per your reply, the error was resolved by replacing

        .def("getName", &Ccy::getName)

with

        .def("getName", &Ccy::getName,
boost::python::return_value_policy<boost::python::copy_const_reference>(
)) 

Regards,
Paul

-----Original Message-----
From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On
Behalf Of Olaf Peter
Sent: Thursday, August 14, 2008 9:46 AM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] Boost.Python: wrapping a method returning const
std::string &

Bilokon, Paul schrieb:
> Hi c++-sig,
> 
> Sorry if this is supposed to be glaringly obvious, but I thought 
> std::string types were pretty much fully supported in Boost.Python 
> (looking at Boost 1.35.0).
> 
> I'm trying to wrap a method
> 
>     const std::string& getName( ) const;
> 
> This should be straightforward, right?
> 
> I'm doing it like this:
> 
>     class_<Ccy>("Ccy", init<>())
>         .def("getName", &Ccy::getName)
>     ;
> 
> But in return I'm getting
> 
> Error	6	error C2027: use of undefined type
> 'boost::python::detail::specify_a_return_value_policy_to_wrap_function
> s_
> returning<T>'
> E:\dev\external\boost\boost_1_35_0\boost\python\detail\caller.hpp
> 223	
> 
> Is this because the string is returned by reference? Do I have to wrap

> the method? If so, I would be very much obliged if you could direct me

> to an example.

Cool compiler error, it says what he expected: see
http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/copy_const_refer
ence.html. 
Please google, why this is you friend.


Regards,
Olaf

_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This message is intended only for the personal and confidential use of the designated recipient(s) named above.  If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited.  This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such.  All information is subject to change without notice.




More information about the Cplusplus-sig mailing list