I know what the diamond problem is I do understand in Java and C++ too. but the problem is that I didn't understand is what's actually the virtual
keyword does to solve the problem. I did not find that what exactly is?
If anyone can give me the short explain with example that is something appreciated.
In below code I use A, B, C, D as well to understand easily.
#include<iostream>
using namespace std;
class PersonA {
public:
PersonA(int x) { cout << "PersonA::PersonA(int ) called" << endl; }
PersonA() { cout << "PersonA::PersonA() called" << endl; }
};
class FacultyB : virtual public PersonA {
public:
FacultyB(int x):PersonA(x) {
cout<<"FacultyB::FacultyB(int ) called"<< endl;
}
};
class StudentC : virtual public PersonA {
public:
StudentC(int x):PersonA(x) {
cout<<"StudentC::StudentC(int ) called"<< endl;
}
};
class TAD : public FacultyB, public StudentC {
public:
TAD(int x):StudentC(x), FacultyB(x) {
cout<<"TAD::TAD(int ) called"<< endl;
}
};
int main() {
TAD ta1(30);
}