Using STL containers in a header file

Is it possible to use STL containers in a class's header file? Meaning, can I declare and then construct say, a queue in a class I am writing? How would I make sure that #include <queue> doesn't appear multiple times?
Yes, you can. You don't need to make sure includes only appear once, because they all have include guards. Your headers have include guards too. Right?
Last edited on
Yes. But this returns an error on the queue line:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef BASECARDGAME_H
#define BASECARDGAME_H
#include <queue>


class baseCardGame
{
    public:
        baseCardGame();
        virtual ~baseCardGame();
    protected:
    private:
    queue<int> deck;

};

#endif // BASECARDGAME_H 
Because, like everything in the Standard Template Library, queue is in the std namespace, meaning you must either write std::queue, or put using namespace std; or using std::queue; at the top.
Doh! Amazing how little things like that can make you frustrated for hours and someone else can take one look and it's done.
Topic archived. No new replies allowed.