Home > Back-end >  Virtual base class that shows the constructor of why its derived class members of the derived class
Virtual base class that shows the constructor of why its derived class members of the derived class

Time:11-22

#include
using namespace std;
The class base0 {
Public:
Base0 (int I) : var0 (I) {}

Int var0;
Void fun0 () {
Cout<& lt;" Member of base0 "& lt; };
The class base1: virtual public base0 {
Public:
Base1 (int x) : base0 (x) {}
};
The class base2: virtual public base0 {
Public:
Base2 (int y) : base0 (y) {}
};
The class derived: public base1, public base2 {
Public:
Derived (int x, int y, int z) : base1 (x), base2 (y) and var (z) {}//this error to invoke base0 default constructor

Int var.
Void fun () {cout<& lt;" Member of the derived "& lt; };
Int main () {
Derived a (1, 2, 3);
A.f un0 ();

return 0;
}
When creating a derived object has joined the already give base0 constructor spread constructed base0 object is what to call it the default
  • Related