Calling C++ static methods

1,216 views
Skip to first unread message

Wichert Akkerman

unread,
Feb 11, 2011, 6:18:17 AM2/11/11
to cython...@googlegroups.com
I have a C++ class which has a static method:

class Foo {
public:
static void bar();
};

I C++ you normally call that like this:

Foo::bar();

I am trying to write a small cython method which calls that method:

cdef cppclass Foo:
static void bar()

cdef bar(region_type region):
Foo::bar()


but that results in a cython compile error on the Foo::bar() statement.
Is that a bug, or is there another way to call static methods?

Wichert.

Stefan Behnel

unread,
Feb 11, 2011, 6:51:31 AM2/11/11
to cython...@googlegroups.com
Wichert Akkerman, 11.02.2011 12:18:

I didn't try your example, but in any case, the correct syntax for calling
a function in Python (and Cython) is using the dot notation, i.e. Foo.bar().

Stefan

Wichert Akkerman

unread,
Feb 11, 2011, 7:28:03 AM2/11/11
to cython...@googlegroups.com
Hi Stefan,

thanks for the quick response.


That fixes the cython error, but the results in a C++ compilation error:
expected unqualified-id before ‘.’ token

Wichert,

Robert Bradshaw

unread,
Feb 11, 2011, 1:02:06 PM2/11/11
to cython...@googlegroups.com

Use c-name specifiers to hack around this, i.e.

cdef extern from "...":
cdef cppclass Foo:
...
cdef Foo_bar "Foo::bar""() # not declared as a memeber

- Robert

Robert Bradshaw

unread,
Aug 24, 2016, 3:40:19 AM8/24/16
to cython-users
Just following up on this, the suggested hack is no longer needed as static methods are supported directly: http://docs.cython.org/en/latest/src/userguide/wrapping_CPlusPlus.html#static-member-method
Reply all
Reply to author
Forward
0 new messages