views:

166

answers:

4

My C++ is a bit rusty so...

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

that gives me the oh so nice error message:

test.cpp:2: syntax error before `;' token

What the heck can I even Google for in that...

+14  A: 

The names of the C++ Standard library are in namespace std

#include <list>
typedef std::list<int> foo;
Johannes Schaub - litb
+5  A: 

list<> is in the STD namespace. This should work fine:

#include<list>
typedef std::list<int> foo;
greyfade
Drat. Too slow. :(
greyfade
+7  A: 

You are expecting the list to be in global namespace. But is defined inside std namespace. Hence either you should use using namespace std; or expliictly specify the namespace as std::list; I personally prefer the second option.

Naveen
Don't forget the using-declaration: "using std::list;". If I'm referencing something a lot (cout, endl), I'll bring them into the current scope without bringing the rest of std.
Bill
A: 

Alternatively you could do,

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

if you don't want to type std:: everywhere.

eed3si9n
Actually, I consider this bad advice. (I don't want to start all over The Holy Namespace Debate here, but I stick to my opinion nevertheless.)
sbi