Jul 14, 2024
Employee
class with name
, company
, and age
attributes.class Employee {
public:
std::string name;
std::string company;
int age;
};
;
after class declarationclass Employee {
public:
Employee(std::string name, std::string company, int age) {
this->name = name;
this->company = company;
this->age = age;
}
};
name
, company
, and age
as private and using getters and setters to access them.void setName(std::string name) { this->name = name; }
std::string getName() { return name; }
Developer
and Teacher
classes inheriting from Employee
classclass Developer : public Employee {
public:
std::string favoriteProgrammingLanguage;
};
Employee* e = &developer;
e->work();
virtual
to enable derived class overrides.