#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),Person(x) {
cout<<"TA::TA(int ) called"<< endl;
}
};
int main() {
cout<<"size Person "<<sizeof(Person)<<"\n";
cout<<"size Faculty "<<sizeof(Faculty)<<"\n";
cout<<"size Student "<<sizeof(Student)<<"\n";
cout<<"size TA "<<sizeof(TA)<<"\n";
}
Output:
size of Person 1
size of Faculty 8
size of Student 8
size of TA 16
what internally happens in compiler? I think compiler definitely adds VPTR if it adds VPTR then is it assign to NULL?
for virtual destructor also compiler adds VPTR how compiler resolves everything internally ?