我的C++是有點生疏所以...這個C++代碼有什麼問題?
#include<list>
typedef list<int> foo;
,讓我的哦,這麼好的錯誤消息:
TEST.CPP:2:`之前語法錯誤;」令牌
到底能我連谷歌在這...
我的C++是有點生疏所以...這個C++代碼有什麼問題?
#include<list>
typedef list<int> foo;
,讓我的哦,這麼好的錯誤消息:
TEST.CPP:2:`之前語法錯誤;」令牌
到底能我連谷歌在這...
您期待列表位於全局命名空間中。但是在std命名空間內定義。因此,你應該使用using namespace std;
或明確指定名稱空間爲std::list;
我個人更喜歡第二個選項。
的C++
標準庫的名字在命名空間std
#include <list>
typedef std::list<int> foo;
list<>
什麼是性病的命名空間。這應該工作得很好:
#include<list>
typedef std::list<int> foo;
Drat。太慢了。 :( – greyfade 2009-09-20 06:20:59
或者你可以做,
#include<list>
using namespace std;
typedef list<int> foo;
,如果你不想鍵入std::
無處不在。
實際上,我認爲這個不好的建議(我不想從這裏開始討論名義空間的爭論,但我堅持我的意見。) – sbi 2009-09-20 20:58:14
不要忘記使用聲明:「using std :: list;」。如果我引用了很多東西(cout,endl),我會將它們帶入當前範圍,而不會將std的其餘部分 – Bill 2009-09-20 14:36:22