[C++-sig] A couple of simple BP V2 questions

David Abrahams dave at boost-consulting.com
Wed Nov 13 00:14:52 CET 2002

"Scott A. Smith" <ssmith at magnet.fsu.edu> writes:

> Hi Dave,
>> Oh, well of course you can write:
>>     scope().attr("PLANCK") = PLANCK;
> Yep, I did a "du-oh" just after sending off my last e-mail. Now I am
> trying to figure out how to deal with a class member function that
> returns const std::string&. I assume I need to figure out call
> policies, but the tutorial info isn't real clear to me. 

Then please read the reference manual, which describes Call Policies
in detail.

> I just have
> const std::string& myclass::myfunction()
> The compiler complains when I add this to the class using
> .def("myfunction", &myclass::myfunction)
> but since the function takes no arguments I cannot figure out how
> or if I need to modify it with 

> return_internal_reference and with_custodian_and_ward. Or perhaps
> something else that sets the call policy....

How about return_value_policy<copy_const_reference>?
Is it important to avoid copying the resulting string?

                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

More information about the Cplusplus-sig mailing list