non-virtual-bases/try-repeated-inheritance.cc - Attempting repeated inheritance in C++. | Lecture 5 - slide 21 : 40 Program 1 |
#include <iostream> #include <string> using namespace std; class A { public: int a; A(int a): a(a){} }; class D : public A, public A { // error: duplicate base type A invalid public: int d; D(): d(9){} }; int f(D &x){ // problem: how should we select one or the other A branch? cout << x.A::a << endl; cout << x.d << endl; } int main(){ D d; f(d); }