What's wrong with this C ++ code?

My C ++ is a little rusty, so ...

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

      

which gives me a good error message:

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

What the heck can I even google this ...

+2


source to share


4 answers


The list is expected to be in the global namespace. But it is defined inside the std namespace. Hence, either you must use using namespace std;

or explicitly specify the namespace as std::list;

. I personally prefer the second option.



+7


source


C++

Standard library names are in namespacestd



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

      

+14


source


list<>

is in the STD namespace. This should work fine:

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

      

+5


source


Alternatively, you can do,

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

      

if you don't want to type std::

everywhere.

0


source







All Articles