I have a very simple c++ class defined in foo.cpp
:
class Foo
{
int x;
public:
Foo()
{}
Foo(int _x)
: x ( _x )
{}
int getX() { return x; }
void print()
{ std::cout << "Foo { " << x << "}" << std::endl; }
};
In trying to wrap it with cython, I create foo.pxd
with the following declaration:
cdef extern from "foo.cpp":
cdef cppclass Foo:
Foo() except +
Foo(int) except +
int x
int getX()
void print()
However, on attempting to build this, and cimport
it into my pyx
source file, it gives me the following compilation error:
Error compiling Cython file:
------------------------------------------------------------
...
cdef cppclass Foo:
Foo() except +
Foo(int) except +
int x
int getX()
void print()
^
------------------------------------------------------------
foo.pxd:9:13: Empty declarator
Error compiling Cython file:
------------------------------------------------------------
...
cdef cppclass Foo:
Foo() except +
Foo(int) except +
int x
int getX()
void print()
^
------------------------------------------------------------
foo.pxd:9:13: Syntax error in C variable declaration
I was attempting to follow this tutorial, however it doesn't seem to work in my case. Even modifying it such that the Foo::print
method takes an integer argument y
, and updating foo.pxd
to void print(int)
, I get the same exact error.
What could I be doing wrong, and why am I getting this behavior?