我有enum
类型roles
,如下所示:
enum roles { reader, librarian, dataManager, administrator };
class Role
{
public:
Role();
void setRole(roles roleID);
roles getRole();
~Role();
private:
roles roleID;
};
假设每个读者都有searchForBook()
,seeNotifications()
两个函数,每个图书馆员都有add()
,removeFromSystem()
两个函数。
我应该怎么做才能实现上述内容,以便在完成后,代码可能是这样的(实际上,这段代码在C ++中不起作用,应该是这样的):
enum roles { reader, librarian, dataManager, administrator };
class Role
{
public:
Role();
void setRole(roles roleID);
roles getRole();
switch (roleID)
{
case reader: //they have two functions to be used, I mean
searchForBook();
seeNotifications();
case librarian: //they have two functions to be used, I mean
add();
removeFromSystem();
}
~Role();
private:
roles roleID;
};