[C++-sig] shared_ptr converters
Nicodemus
nicodemus at globalite.com.br
Tue Apr 15 12:48:41 CEST 2003
Hamilton Feltman wrote:
>Hello! So I'm not the only one stumbling on this. Unfortunately I don't
>have an answer, but I boiled down the code to demonstrate the problem:
>
>
>struct SomeClass
>{
> int a, b;
> SomeClass (int a, int b) : a(a), b(b) {}
>};
>
>boost::shared_ptr<SomeClass> SomeFunction (int a, int b)
>{
> return boost::shared_ptr<SomeClass> (new SomeClass(a, b));
>}
>
>BOOST_PYTHON_MODULE(Test)
>{
> class_<SomeClass>("SomeClass", init<int, int>());
> def ("SomeFunction", SomeFunction);
>}
>
>
I believe the conversion of shared_ptr's are automatic only from-python.
For to-python conversions you need to specify the holder for your class:
class<SomeClass, boost::shared_ptr<SomeClass> >(...);
That should work. Problem with my example is that, even thought the
converter is being registered, it's not working. 8(
>>>>from Test import *
>>>>
>>>>
>import Test # dynamically loaded from Test_d.dll
>[9005 refs]
>
>
>>>>obj = SomeFunction (3,3)
>>>>
>>>>
>Traceback (most recent call last):
> File "<stdin>", line 1, in ?
>TypeError: No to_python (by-value) converter found for C++ type: class
>boost::shared_ptr<struct SomeClass>
>[9021 refs]
>
>Anyone have a clue? Seems like a fairly straightforward conversion, but
>I don't know enough about boost python, or all the internal amazements
>going on inside it (but learning quick). I'm running vc7 on windows.
>
>
Hope that helps,
Nicodemus.
More information about the Cplusplus-sig
mailing list