Why does the next class have a virtual table?

Suppose I have a diamond inheritance situation as follows:

class A{ public: virtual void foo(){}; }; class B: public virtual A{ public: virtual void foo(){}; }; class C: public virtual A{ public: virtual void foo(){}; }; class D: B, C{}; 

The last line gives a compilation error, citing ambiguity. As far as I understand, the problem is that the compiler does not know which foo to put vtbl in D, but why not even be vtbl for D if it does not define any native virtual functions?

+6
c ++ multiple-inheritance vtable
source share
1 answer

You inherit classes containing virtual functions. Therefore, your class has virtual functions. It is so simple.

+7
source share

All Articles