samedi 9 juillet 2016

Initialization lists in Cython c++ classes


In the "experimental_cpp_class_def" functionality where you can write a C++ class in Cython (https://github.com/cython/cython/blob/master/tests/run/cpp_classes_def.pyx), is there syntax for initialization lists? This seems necessary to control which constructors get called in inherited classes.

Example

C++ "myclass.h":

namespace myclass
{

class MyClass {
      MyClass() { };
      MyClass(int x) { };
};

Cython:

cdef extern from "myclass.h" namespace "myclass":
    cdef cppclass MyClass:
         MyClass()
         MyClass(int x)

cdef cppclass SubClass(MyClass):
         def __init__(int x):
             # Implicitly calls MyClass::MyClass(), but would like to
             # call MyClass::MyClass(x)            
             pass

Aucun commentaire:

Enregistrer un commentaire