C ++ - Klasse in Fused Type

Ich möchte Python-Wrapper für eine Reihe von C ++ - Klassen implementieren. Irgendwo in pxd habe ich:

cdef cppclass FooImpl1:
    FooImpl1()
    int foo()

cdef cppclass FooImpl2
    FooImpl2()
    int foo()

Ich frage mich, ob ich so etwas in pyx python wrapper schreiben kann:

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()

Gibt es eine Möglichkeit, das erwartete Verhalten zu erreichen? FooImpl1 und FooImpl2 teilen keine abstrakte Schnittstelle, sie sind Vorlagenspezialisierungen einer Klasse.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage