fork download
  1. #include<iostream>
  2. using namespace std;
  3. class Person {
  4. public:
  5. Person(int x) { cout << "Person::Person(int ) called" << endl; }
  6. Person() { cout << "Person::Person() called" << endl; }
  7. void x() { cout << "X\n"; }
  8. };
  9.  
  10. class Faculty : virtual public Person {
  11. public:
  12. Faculty(int x):Person(x) {
  13. cout<<"Faculty::Faculty(int ) called"<< endl;
  14. }
  15. void y() { cout << "Y\n"; }
  16. };
  17.  
  18. class Student : virtual public Person {
  19. public:
  20. Student(int x):Person(x) {
  21. cout<<"Student::Student(int ) called"<< endl;
  22. }
  23. void z() { cout << "Z\n"; }
  24. };
  25.  
  26. class TA : public Faculty, public Student {
  27. public:
  28. TA(int x):Student(x), Faculty(x), Person(x) {
  29. cout<<"TA::TA(int ) called"<< endl;
  30. }
  31. };
  32.  
  33. int main() {
  34. Person* p = new TA(30);
  35. p->x();
  36.  
  37. Person* s = new Student(25);
  38. //s->y();
  39. //s->z();
  40.  
  41. }
Success #stdin #stdout 0s 4468KB
stdin
Standard input is empty
stdout
Person::Person(int ) called
Faculty::Faculty(int ) called
Student::Student(int ) called
TA::TA(int ) called
X
Person::Person(int ) called
Student::Student(int ) called