[C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type:

tALSit de CoD talsit at talsit.org
Tue Aug 24 10:23:24 CEST 2004


YES!!
Thanks heaps, that solved it perfectly...
I have been bashing my head a bit on that one... couldn't quite figure  it
out. I don't completely comprehend templates, and the wierd and  wonderful
way that it works...

Now, just a quicky:
If i have two class methods:
class A {
public:
     const std::string & getName () { return m_name; }
private:
     std::string m_name;
};

class B {
public
     const A * getA () const { return m_a; }
           A * getA ()       { return m_a; }
private:
     A * m_a;
};

How do i wrap that method? I need them both there, but when i try to  wrap
it like this:


class_ <B> ("B")
     .def ("getA",  &B::getA, return_internal_reference <> ())
;

It complains quite a lot, since it is an overloaded method.


David Abrahams wrote:

> "tALSit de CoD" <talsit at talsit.org> writes:
>
>
>>I've writen up a complete file that demostraits what i'm trying to do,
i've posted it up here:
>>http://talsit.org/image/boost_python_test.cpp
>>Basically, i have an object (class B) that has a std::vector <A*>. If i
return a reference to that vector, how can i iterate through it. If i do
it with the straight iterator method, like i do with other basic data
types (unsigned int), it complains about not been able to convert from A
*. If i do it with the range method as suggested, it says that it can
convert from A.
>
>
> Because you wrapped A as noncopyable, it can't copy the A referenced by
the iterator into a new Python object.  You can fix this by
> removing the noncopyable, or by using the 2nd form of range, instead of
the first:
>
>   class_ <std::vector <A *> > ("AList")
>     .def("__iter__", range<return_internal_reference<> >(ABegin, AEnd))
>                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 	;
>
>
>>Thing is, I don't know if i'm even doing the range method correctly.
>
>
> You are, but see above.
>
>







More information about the Cplusplus-sig mailing list