klasa c ++ w typie fused

Chcę zaimplementować opakowanie python dla grupy klas c ++. Gdzieś w pxd mam:

cdef cppclass FooImpl1:
    FooImpl1()
    int foo()

cdef cppclass FooImpl2
    FooImpl2()
    int foo()

Zastanawiam się, czy mogę napisać coś takiego w opakowaniu Pythona Pythona:

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

Czy istnieje sposób na osiągnięcie oczekiwanego zachowania? FooImpl1 i FooImpl2 nie dzielą abstrakcyjnego interfejsu, są to specjalizacje szablonów klasy.

questionAnswers(1)

yourAnswerToTheQuestion