[C++-sig] Py++ tutorial

Roman Yakovenko roman.yakovenko at gmail.com
Mon Sep 18 21:46:43 CEST 2006


On 9/18/06, thor.arne.johansen at ibas.no <thor.arne.johansen at ibas.no> wrote:
>
> I've just tried the tutorial code for Py++. (hello_world.cpp)
>
> The code seem to build OK, but the following fails:
>
> >>> a = hw.animal('Dog')
> >>> a.name()
> 'Dog'
> >>> a.get_name_ptr()
> 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> >
> >>>
>
> Is this the expected behavior?

I think yes. The main purpose of the tutorials I built, was to
introduce Py++ and
not Boost.Python.

Here is the context we are talking about:

struct animal{

    animal( const std::string& name="" )
    : m_name( name )
    {}

    const std::string* get_name_ptr() const
    { return &m_name; }

private:
    std::string m_name;

};

I set return_internal_reference call policies for get_name_ptr member function.
Obviously, strings are immutable types in Python so they can not be changed
from C++.

> If so, how do I 'register' a Python class of the correct type (using py++)

In this case you don't. Boost.Python already did it for you. I think
that in this
case I should change the call policies ( or to provide better example ).

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list