2

我的 C++ 有点生锈,所以...

#include<list>
typedef list<int> foo;

这给了我非常好的错误信息:

test.cpp:2: `;' 之前的语法错误 令牌

我什至可以用谷歌搜索什么......

4

4 回答 4

14

C++标准库的名称在命名空间中std

#include <list>
typedef std::list<int> foo;
于 2009-09-20T06:19:22.837 回答
7

您期望该列表位于全局命名空间中。但是在 std 命名空间内定义。因此,您应该使用using namespace std;或明确指定命名空间,因为std::list;我个人更喜欢第二个选项。

于 2009-09-20T06:21:52.290 回答
5

list<>位于 STD 命名空间中。这应该可以正常工作:

#include<list>
typedef std::list<int> foo;
于 2009-09-20T06:20:24.207 回答
0

或者你可以这样做,

#include<list>
using namespace std;
typedef list<int> foo;

如果你不想std::到处打字。

于 2009-09-20T06:22:59.717 回答