'list' does not name a type

1
2
3
4
5
6
7
8
9
10
//header.h

#include <list>

class a
{
private:
	list<int> a;
public:
};


build message: error: 'list' does not name a type

How can I solve this problem? Thanks a lot.
Last edited on
it will be either:
1
2
3
4
5
6
7
8
9
10
11

#include <list>

using namespace std;

class a
{
private:
	list<int> a;
public:
};


or
1
2
3
4
5
6
7
8
9

#include <list>

class a
{
private:
	std::list<int> a;
public:
};


you forgot to include the namespace info to access the correct scope of <list>
List is part of the std namespace. There are two ways to solve your problem:

After your include(s), add:
 
using namespace std;  

Then your code should work fine. Alternatively, replace line 8 with:
 
std::list<int> a;

Either way works, but if you use the second method, every usage of list/vector/cout/etc will require you to put std:: in front of the word. If you plan to use a lot of things from the std namespace, you might as well use the first method.
Last edited on
Thank Azagaros and Gaminic, I forget the namespace std.
Thank you very much.
Topic archived. No new replies allowed.