Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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);
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: sort vector in c 
Cpp :: c++ freecodecamp course 10 hours youtube 
Cpp :: cocos2d c++ linux 
Cpp :: easy way to encrypt a c++ file line by line 
Cpp :: c++ regex to validate indian phone number pattern 
Cpp :: Runtime error(Exit status:153(File size limit exceeded)) c++ 
Cpp :: stack using cpp 
Cpp :: c++ thread id 
Cpp :: SDL_BlitSurface 
Cpp :: sfml get position 
Cpp :: how to change the default camera speed values opengl 
Cpp :: C++ check if thread is joinable 
Cpp :: ordine crescente "senza" vettori in c++ 
Cpp :: multiple inheritance c++ 
Cpp :: esp8266 wifi.localip() to string 
Cpp :: 01matrix 
Cpp :: c++ CRL multiline string 
Cpp :: type defination in C++ 
Cpp :: Remove the jth object from the subset 
Cpp :: comment savoir si un nombre est premier c++ 
Cpp :: vector of vector definaion in c++ 
Cpp :: c++ format number thousands separator 
Cpp :: multilevel inheritance in c++ private method 
Cpp :: Check if two stacks are the same using C++ 
Cpp :: converting a for loop to a while loop C++ 
Cpp :: convert ros time to double 
Cpp :: Casino Number Guessing Game - C++ 
Cpp :: fenwick tree 
Cpp :: what is push() c++ 
Cpp :: binary add using strings 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =