[C++-sig] std::string ?

David Abrahams dave at boost-consulting.com
Mon Apr 21 18:07:11 CEST 2003


tALSit de CoD <talsit at talsit.org> writes:

> Ok... thanks for that before, now i think i'm actually starting to
> understand how this big scary monster works, thanks!
>
> Now, i got another question. If i got this:
>
> class cKernel {
>          const std::string & getName () const { return m_name; }
> }
>
> and I wrap it like so:
>
> namespace kikura {
>          BOOST_PYTHON_MODULE (kikura) {
>                  class_ <cKernel> ("cKernel", no_init)
>                          .def ("getName", cKernel::getName,
>                          return_internal_reference <> ());
> }
>
> When I go to use that method in python it gives me this error:
>
>  >>> k.getName ()
> Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
> TypeError: No Python class registered for C++ class class
> std::basic_string<char,struct std::char_traits<char>,class
> std::allocator<char> >
>
> But if i change the method call to not return a reference, and wrap it
> without a call policy, it works just fine. Am i missing something
> here, or do i have to do it another way? As in use
>
> copy_const_reference or similar?
  ^^^^^^^^^^^^^^^^^^^^

Yes.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list