G
In the first place, according to your drawing, the hierarchy must be constructed as follows:class B {
int a;
public:
//любой конструктор должен инициализировать все члены, дабы сохранить инвариант
B():a(0) { };
B(int x) { a = x; }
virtual void show_B() { cout << "B= " << a << "\n"; }
};
class D1 : virtual public B {
int b;
public:
D1(int x, int y) : B(y) { b = x; };
void show_D1() { cout << "D1= " << b << "\n"; show_B(); }
};
//по указанной схеме D2 и D1 должны наследовать один и тот же объект
class D2 : virtual protected B {
int c;
public:
D2(int x, int y) : B(y) { c = x; };
void show_D2() { cout << "D2= " << c << "\n"; show_B(); }
};
//тут нет требований иметь виртуального наследования
//(нет нужды наследовать один и тот же объект)
class D3 : public D2 {
int d;
public:
D3(int x, int y, int z, int i) : D2(y, z) { d = x; }
void show_D3() { cout << "D3= " << d << "\n"; show_D2(); }
};
class D4 :protected D1, private D3 {
int e;
public:
D4(int x, int y, int z, int i, int j, int u, int k) : D1(y, z), D3(i, j, u, k) { e = x; }
void show_D4() { cout << "D4= " << e << "\n"; show_D1(); show_D3(); }
};
Then there's no problem with the designers, because everyone inherits one particular base class object and has a default designer.The way you did, to design the facility. temp1 We need to design. D1 and D3and the next one has виртуальный базовый класс D2which means that any target class has to design it because the object is the same but the class designer. D4 not initial D2that's why it's called him.D2default designerthat you just didn't write... And don't forget that any designer should initialize the members of the class if they're not initialized. Keep the inventor. Always.!