класс с ++ в слитном типе
Я хочу реализовать оболочку Python для нескольких классов C ++. Где-то в pxd у меня есть:
cdef cppclass FooImpl1:
FooImpl1()
int foo()
cdef cppclass FooImpl2
FooImpl2()
int foo()
Интересно, могу ли я написать что-то вроде этого в оболочке Pyx Python:
ctypedef fused FooImpl:
FooImpl1*
FooImpl2*
cdef class Foo:
cdef FooImpl impl
def __cinit__(self, int selector):
if selector == 1:
self.impl = new FooImpl1()
else:
self.impl = new FooImpl2()
def func(self):
# depending on the object stored in impl FooImpl2::foo or FooImpl1::foo
# will be called
return self.impl.foo()
Есть ли способ достичь ожидаемого поведения? FooImpl1 и FooImpl2 не делаютне разделяя абстрактный интерфейс, они являются шаблонными специализациями класса.