Question

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...

Was it helpful?

Solution

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.

OTHER TIPS

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

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

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

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

Alternatively you could do,

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top