错误:预期";"

Error : expected a ";"

本文关键字:预期 错误      更新时间:2023-10-16

这是一个愚蠢的问题,但我有一个错误:

#include <unordered_set> 
std::unordered_set<std::string> ValidValues **{**"one", "two", "three"};

错误:预期a;出现在第一个括号中。与"集"相同。

重新启动视觉工作室和计算机。

这有效:

#include <string>
#include <unordered_set> 
std::unordered_set<std::string> ValidValues {"one", "two", "three"};

使用GCC 4.4 ,Clang 3.1 和MSVS2013 。

MSVS2010/2012不支持称为列表初始化的语言功能,Wich是您正在做的。