Cython : exposing C++ classes with nested typedef (s)

荒凉一梦 提交于 2019-12-06 10:41:33

I have gotten nested definitions to work using the namespace keyword, specifying the nested declaration. Like, if you have e.g. the following in a C++ header named mystuff.hpp:

namespace MyStuff {
    struct Outer {
        struct Inner {
            int value;
        };
        Inner member;
    };
}

… you can encython those structures like so:

cdef extern from "mystuff.hpp" namespace "MyStuff::Outer":
    cppclass Inner:
        int value

cdef extern from "mystuff.hpp" namespace "MyStuff":
    cppclass Outer:
        Inner member

… it reads more coherently if you actually have everything in C++-land wrapped in a namespace, as written (otherwise the second cdef has no namespace in its declaration, which looks wierder IMO).

I have a number of real-world currently-working examples of this: one such example is here, another one is here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!