list does not name a type

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef QUEUE_H_
#define QUEUE_H_

// Get a definition for null
#include <iostream>

// Use STL list as a backend for queue
#include <list>
#include <string>

/*
 * OVERVIEW: A last-in first-out queue implemented using STL list
 */
template<typename T>
class Queue {
public:
	void enqueue(T elt);
	T dequeue(void);
private:

	// Private list that is the queue
	std::list<int> queue; 
};

#endif /* QUEUE_H_ */ 


Inside of this file, if I run g++ -O thisfile.h I get a 'list' does not name a type error.

If I put a std::string s in the private: part of the class, I don't get this error. What is going on?
I don't know where your problem is, but i know you shouldn't compile .h files alone. Your file contains only declarations and no variable to allocate or code to execute so you won't get much by compiling it alone. Compile a cpp file that contains some code or data, and that includes your header, and see if you get an other result?
Good suggestion. The error left a bit ago, I'm not sure what I did, but the error went away after I started implementing the .h file in a .cpp file. It sound like you were right. I'll keep that in mind for the future.
Topic archived. No new replies allowed.