Virtual inheritance and static inheritance - mixing in C++

前端 未结 6 679
误落风尘
误落风尘 2020-12-29 13:33

If you have something like this:

#include 

template class A
{
public:
    void func()
    {
        T::func();
    }
};

c         


        
6条回答
  •  感动是毒
    2020-12-29 14:17

    In your particular example, there's no need for dynamic dispatch because the type of c is known at compile time. The call to B::func will be hard coded.

    If you were calling func through a B*, then you would be calling a virtual function. But in your highly contrived example, that would get you to B::func once again.

    It doesn't make much sense to talk about dynamic dispatch from an A* since A is a template class - you can't make a generic A, only one that is bound to a particular subclass.

提交回复
热议问题