Lionel Data | 3 Aug 11:41 2010
Picon

Re: C++ wrapping : Template bug ?



2010/8/3 Lionel Data <lionel.data <at> gmail.com>
Hi, I am experiencing a strange behavior of Cython when trying to wrap STL containers.

I copy/pasted the code available here : http://wiki.cython.org/WrappingCPlusPlus#Templates

This works fine if I keep "int" as the template parameter. It still works fine if I put "int *".

If I now add:

cdef extern from "test.h":
    cdef cppclass TestClass:
        TestClass()

below the list declaration, it still works fine with "TestClass" as the template param.

But surprisingly, it does not even compile to c++ if I write "TestClass *".
The error message is:

cdef vector[TestClass *] *v = new vector[TestClass *]()
                      ^
------------------------------------------------------------

/home/lionel/test/test_cython.pyx:21:23: Expected an identifier or literal

It seems like a bug, but I'm quite tired today so I might have missed something. If it is indeed a bug, what do you suggest as a workaround ?

(I use the repository "trunk" version)

Lionel


Well, it wasn't that hard to fix after all, a "ctypedef struct PTestClass" did the job, along with a "typedef TestClass * PTestClass" in the .h file.


Lionel

Gmane