Professional Documents
Culture Documents
Multi Inheritence
Multi Inheritence
#include <string>
// Base class
class Person {
private:
std::string name;
int age;
public:
void displayInfo() {
std::cout << "Name: " << name << ", Age: " << age << std::endl;
};
private:
std::string employeeId;
public:
// Constructor for Employee class, calling the base class constructor explicitly
void work() {
std::cout << "Employee with ID " << employeeId << " is working." << std::endl;
};
// Second derived class (inherits from Person)
private:
std::string studentId;
public:
// Constructor for Student class, calling the base class constructor explicitly
void study() {
std::cout << "Student with ID " << studentId << " is studying." << std::endl;
};
// Derived class with multiple inheritance (inherits from Employee and Student)
public:
// Constructor for WorkingStudent class, calling the constructors of both base classes
void doBoth() {
};
int main() {
myWorkingStudent.work();
myWorkingStudent.study();
myWorkingStudent.doBoth();
return 0;