我有基类Employee
和派生类concreteEmployee
。
class Employee {
virtual void &getStatus() {} ??
}
class concreteEmployee : public Employee {
public:
enum class Status {
Intern,
Worker,
Manager
};
Status status;
void setStatus() {
?????
}
... &getStatus() { // virtual from Employee
return Status; ???
}
我的指针向量为vector<shared_ptr<Employee>> Firm;
,我通过引用sourceEmployee
传递。
我想做的是:
在雇用“ Worker
”之类的新员工时设置具体身份。
void hireEmployee(vector<shared_ptr<Employee>>& sourceEmployee) {
sourceEmployee.emplace_back(new concreteEmployee(fillName, fillSurname));
sourceEmployee.back()->status = ???
我想这样做,而不是在std::string Status = "Worker"
等中使用concreteEmployee
字段。
和经典的设置器/获取器。
我想从concreteEmployee
类中获取Employee
的状态并将其打印在某处。我有矢量派生对象(使用std::shared_ptr
),并且想要得到这样的状态?
void employeeShowcase(const vector<shared_ptr<Employee>>& sourceEmployee) {
cout << sourceEmployee[index]->getStatus()
... // output should be like i.e "Worker"
}
答案 0 :(得分:1)
如果班级的消费者应该可以看到您的Employee状态,则表明您必须在Employee
而不是ConcreteEmployee
的范围内定义该枚举