奇怪的编译错误:ISO C ++禁止声明'set'没有类型

时间:2011-05-19 08:39:21

标签: c++ compiler-errors set

  

可能重复:
  Help with error: ISO C++ forbids declaration of 'vector' with no type

我在我的代码中使用了set,​​如下所示:

#include <set> 

set<int> followers; //line 36

当我使用g ++编译我的代码时,它会输出以下错误消息:

myCode.cpp:36: error: ISO C++ forbids declaration of ‘set’ with no type  
myCode.cpp:36: error: expected ‘;’ before ‘<’ token

我在这里做错了什么?

3 个答案:

答案 0 :(得分:11)

您忘记指定名称空间:std::set<int> followers;

以下是完全发生的事情:因为你没有指定命名空间编译器遇到一个未知符号set,因为它是第一次出现它决定它是一个声明:在C中可以声明{{1没有指定类型的变量。 C ++明确禁止这种类型的声明,因此错误。

答案 1 :(得分:2)

尝试添加using namespace std,或者只使用std::set<int>

答案 2 :(得分:1)

或者您可以通过

导入设置标识符
using std::set;

然后

set<int> something;
相关问题