C++ nested class name cannot be accessed

173 views
Skip to first unread message

Wei Wu

unread,
Mar 5, 2011, 3:41:14 AM3/5/11
to cython...@googlegroups.com
According to the documentation
(http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html#nested-class-declarations),
Cyhon support wrapped c++ declaration (and the idea of native c++
support is really cool). But I found that the inner class name can be
accessed only if the outer class is defined with template.

Here is an example:

a.h
------
template<typename T>
class A
{
public:
class B
{};
};

class C
{
public:
class B
{};
};


test.pyx
---------
cdef extern from "a.h":
cdef cppclass A[T]:
cppclass B:
pass

cdef cppclass C:
cpplcass B:
pass


def main():
cdef A[int].B a_b # ok
cdef C.B c_b # error: 'C' is not a cimported module

I thought the way of accessing the name of nested class was using '.'
compared to c++'s '::', and the 'C.B' above was interpreted as getting
attribute of a module.
Or am I doing something wrong here?

Robert Bradshaw

unread,
Mar 5, 2011, 1:51:09 PM3/5/11
to cython...@googlegroups.com

Looks like a bug (or not implemented feature) in C++ support.
http://trac.cython.org/cython_trac/ticket/659

- Robert

klo...@gmail.com

unread,
Jul 11, 2015, 11:51:29 AM7/11/15
to cython...@googlegroups.com
I just ran into this problem. Looks like the bug has not been fixed yet. Any suggested workarounds?

Cheers,
kloffy

Robert Bradshaw

unread,
Jul 11, 2015, 8:38:17 PM7/11/15
to cython...@googlegroups.com
On Sat, Jul 11, 2015 at 6:55 AM, <klo...@gmail.com> wrote:
> I just ran into this problem. Looks like the bug has not been fixed yet. Any
> suggested workarounds?

Are you trying to do something different than
https://github.com/cython/cython/blob/master/tests/run/cpp_nested_classes.pyx
?
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cython-users...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

klo...@gmail.com

unread,
Jul 12, 2015, 12:34:15 AM7/12/15
to cython...@googlegroups.com
On Sunday, July 12, 2015 at 10:38:17 AM UTC+10, Robert Bradshaw wrote:
On Sat, Jul 11, 2015 at 6:55 AM,  <klo...@gmail.com> wrote:
> I just ran into this problem. Looks like the bug has not been fixed yet. Any
> suggested workarounds?

Are you trying to do something different than
https://github.com/cython/cython/blob/master/tests/run/cpp_nested_classes.pyx
?
 
Yes, the difference is that the external declaration is in a separate pxd file.

cimport cpp_nested_classes_support

cdef cpp_nested_classes_support
.A.B b

Then you get the "'cpp_nested_classes_support.A' is not a cimported module" error.
 
Which gave me an idea:

from cpp_nested_classes_support cimport A

cdef A
.B b

And sure enough that works, so that's my workaround for now, I guess.

Reply all
Reply to author
Forward
0 new messages