在我找到你们的帮助之前,我花了一个多小时研究这个.我正在使用visual studio 2012,我刚刚安装了更新2.
我有这个构造函数
Lexer::Lexer(istream &source1, ostream& listing1)
:source(source1), listing(listing1)
{
vector<string> tempVec = {
"and", "begin", "boolean", "break", "call", "end", "else", "false", "halt",
"if", "input", "integer", "is", "loop", "not", "null", "newline", "or", "output", "procedure"
"return", "then", "true", "var"
};
tokenToStringVector = tempVec;
for (int k= 0; k < tokenToStringVector.size(); k++)
{
string key = tokenToStringVector[k];
lexemeToTokenMap[key] = Token(k); // Function-style type cast
}
}
Run Code Online (Sandbox Code Playgroud)
我的教授写了标题,我写了代码.我收到这个错误,我无法弄清楚:
1>c:\users\sam\dropbox\compiler project\lexical analyzer\lexer.cpp(8): error C2552: 'tempVec' : non-aggregates cannot be initialized with initializer list
1> 'std::vector<_Ty>' : Types with a base are not aggregate
1> with
1> [
1> _Ty=std::string
1> ]
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它不会让我像这样初始化它.我可以创建一个数组,然后一个循环添加到向量,但我已经只是使用向量来填充一个映射,所以必须有一个更合理的方法来做到这一点.
谢谢!你们总是很有帮助!
请注意:如果答案不是简单的格式化错误,请不要更正代码,只需指向正确的方向.这是一个分级任务,我是一个诚实的学生,我想自己学习.
好的,从回复中重新阅读某人发布的SO帖子.
谢谢大家,我想我只需要制作一个阵列.
我的教授告诉我这样做,他使用一些支持这个的Linux gcc编译器.
编辑:好的,所以微软有一个支持这个版本的alpha版本.我想我只是制作一个数组并传输它.
谢谢您的帮助!!!!
| 归档时间: |
|
| 查看次数: |
2460 次 |
| 最近记录: |