Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with this c++ code?

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

like image 453
BCS Avatar asked Feb 25 '26 00:02

BCS


2 Answers

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

#include <list>
typedef std::list<int> foo;
like image 188
Johannes Schaub - litb Avatar answered Feb 27 '26 12:02

Johannes Schaub - litb


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.

like image 22
Naveen Avatar answered Feb 27 '26 14:02

Naveen