[英]Enum as input to constructor c++ eclipse
I have a project in which I need to get Enum as an input from the user and send it to a constructor.. I searched , didn't find something like this on this website,so here is my Class containing Enums, which compiles: 我有一个项目,需要从用户那里获取Enum作为输入并将其发送给构造函数。.我在该网站上搜索,但未找到类似的内容,因此这是我的包含Enums的Class,它进行编译:
class Worker {
public:
string myGender;
enum workerType {DIRECTOR, ACTOR, COPYWRITER, PRODUCER} myType;
Worker::Worker(workerType type,string gend)
{
myType = type;
myGender = gend;
}
this is the relevant method from my main class, from which i perform actions, and this one compiles as well: 这是我的主类中的相关方法,我从中执行操作,该方法也可以编译:
void MovieIndustry::addWorker(Worker::workerType type, string gend)
{
workers.push_back(Worker(type, gend));
break;
}
From my main I want to get an input like: 0, male 我想从我的主输入中输入:0,男性
and to add a Worker instance with parameters myType = DIRECTOR myGender = male 并添加参数为myType = DIRECTOR myGender = male的Worker实例
I tried this, and it doesn't compile: 我试过了,它不能编译:
#include "MovieIndustry.h" //this is not the problem, works for other funcs
int main() {
MovieIndustry cinema;
int numForWorkertype;
string stringForGender;
cin >> numForWorkertype >> stringForGender;
cinema.addWorker(numForWorkertype ,stringForGender);
return 0;
}
serInterface.cpp:54:64: error: no matching function for call to
‘MovieIndustry::addWorker(int&, std::string&)’
HELP..? 救命..?
numForWorkertype is int type. numForWorkertype是int类型。 Cast to Worker::workerType. 强制转换为Worker :: workerType。
cinema.addWorker( (Worker::workerType)numForWorkertype ,stringForGender);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.