Diamond Inheritance Lowest Base Class Constructor

前端 未结 1 409
情书的邮戳
情书的邮戳 2020-12-03 16:03

The Code is as follow :

The Code :

#include 

using namespace std;

class Animal{
   int a;

    public:
    Animal(i         


        
相关标签:
1条回答
  • 2020-12-03 16:31

    The most derived class initializes any virtual base classes. In your class hierarchy, Unknown must construct the virtual Animal base class (e.g. by adding Animal(a) to its initialization list).

    When constructing an Unknown object, neither Fish nor Bird will call the Animal constructor. Unknown will call the constructor for the Animal virtual base.

    0 讨论(0)
提交回复
热议问题