语法从字符串到函数的映射错误

时间:2013-04-23 23:38:02

标签: c++ function map visual-studio-2012 lambda

我在Visual Studio 2012中遇到以下语法错误:

  

1> ... \ documents \ visual studio 2012 \ projects ... \ line.h(21):错误C2143:语法错误:在)'之前缺少“const” / p>

尝试创建以下内容时(在另一个文件中定义)tokenList typedefstd::vector<std::string>

extern std::map<std::string,std::function<std::string (const tokenList& tokens)>> evaluateOperator; //<-- This is the line with the error

我希望做到以下几点:

evaluateOperator["="] = [](const tokenList& tokens) -> std::string
{
    std::string temp("");
            ...
};

我做错了什么? (我对C ++ 11非常陌生)。我还要感谢有关如何解决整个问题的任何建议,即在基于输入字符串的字符串列表中应用函数。谢谢。

编辑:这就是SSCE如此重要的原因 - 我将错误的来源(使用ICC2013之后)定位为错误的代码顺序 - 在地图声明之后出现了typedef。 Idiotic就我而言,但有趣的是,英特尔C ++编译器2013能够立即检测到语法错误的原因,而VC ++却让人头疼。

1 个答案:

答案 0 :(得分:1)

您声明错误的行与C ++ 11独有的语法属性几乎没有关系。除std::function之外,但如果您的编译器不支持它,则表示无法使用语法错误进行编译。

可能错误来自它下面的代码。我不认为VS支持lambdas,这可能是错误的根源。请注意,您的代码在GCC中编译得很好。