Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Lionel Data <lionel.data <at> gmail.com>
Subject: Re: C++ wrapping : Template bug ?
Newsgroups: gmane.comp.python.cython.user
Date: Tuesday 3rd August 2010 09:41:54 UTC (over 6 years ago)
2010/8/3 Lionel Data 

> 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
 
CD: 121ms