Horje
solve diamond inheritance c++ Code Example
solve diamond inheritance c++
//add virtual to the middle subclass to make it a base class

#include<iostream>
using namespace std;
class Person {
public:
    Person(int x)  { cout << "Person::Person(int ) called" << endl;   }
    Person()     { cout << "Person::Person() called" << endl;   }
};
  
class Faculty : virtual public Person {
public:
    Faculty(int x):Person(x)   {
       cout<<"Faculty::Faculty(int ) called"<< endl;
    }
};
  
class Student : virtual public Person {
public:
    Student(int x):Person(x) {
        cout<<"Student::Student(int ) called"<< endl;
    }
};
  
class TA : public Faculty, public Student  {
public:
    TA(int x):Student(x), Faculty(x)   {
        cout<<"TA::TA(int ) called"<< endl;
    }
};
  
int main()  {
    TA ta1(30);
}




Cpp

Related
 convert fahrenheit to celsius Code Example convert fahrenheit to celsius Code Example
intage1 was not declared in this scope C++ Code Example intage1 was not declared in this scope C++ Code Example
cplusplusbtutotrail Code Example cplusplusbtutotrail Code Example
idnefier endl in undefince Code Example idnefier endl in undefince Code Example
create new node in tree Code Example create new node in tree Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9