I am currently learning Inheritance. The code below works just fine.
#include <iostream>
class Student {
protected:
double GPA = 3.12;
};
class Employee {
protected:
int Salary = 1500;
};
class TeachingAssistant: public Student, public Employee {
public:
void Print() {
std::cout << GPA << " " << Salary << "\n";
}
};
int main() {
TeachingAssistant TA;
TA.Print();
}
However this code below does NOT work.
#include <iostream>
class Student {
protected:
double GPA = 3.12;
};
class Employee: public Student {
protected:
int Salary = 1500;
};
class TeachingAssistant: public Student, public Employee {
public:
void Print() {
std::cout << GPA << " " << Salary << "\n";
}
};
int main() {
TeachingAssistant TA;
TA.Print();
}
I only changed one thing in between these two code snippets and it's the addition of "public Student" next to the class Employee. What did I do wrong? Please explain this using simple words/logic.