In C++, what is a virtual base class?

后端 未结 11 2447
一个人的身影
一个人的身影 2020-11-22 00:55

I want to know what a \"virtual base class\" is and what it means.

Let me show an example:

class Foo
{
public:
    void DoSomething() { /* .         


        
11条回答
  •  情书的邮戳
    2020-11-22 01:15

    A virtual base class is a class that cannot be instantiated : you cannot create direct object out of it.

    I think you are confusing two very different things. Virtual inheritance is not the same thing as an abstract class. Virtual inheritance modifies the behaviour of function calls; sometimes it resolves function calls that otherwise would be ambiguous, sometimes it defers function call handling to a class other than that one would expect in a non-virtual inheritance.

提交回复
热议问题