How can recursive polymorphism have the same parameters

Viewed 14

I am experimenting with static polymorphisme.. And by my suprise this piece of code works...

template<typename T, typename ... Ts>
class Beta: public Beta<Ts...>
{
public:
    Beta() {
        std::cout << "*" << std::endl;
    }

    void test() {}
};

template<typename T>
class Beta<T>
{
public:
    Beta() {
        std::cout << "*" << std::endl;
    }

    void test() {}
};

int main()
{
   Beta<uint8t, uint16_t, uint32_t> beta;
   beta.test();
}

The output shows '***' Which (for me) means that all constructors on each level of the recursion have been called. But I don't understand how the invoke of test can be determined by the compiler...

I would expect 3x times the method test() to be part of the instance beta...

0 Answers
Related