Click to See Complete Forum and Search --> : How come I get compiler errors when using the STL inside a class?


nullspace0
April 21st, 2002, 01:00 AM
Hello everyone. I was just wondering why I have been getting compiler errors when I use the STL container classes (such as list) inside my own class definition.

This is a really cut down version of what I have...


#include <list>
#include "Button.h" //my Button class header

class Screen
{
public:
//Stuff Cut Out
private:
list<Button*> pButtonList;
//More stuff cut
};




So, basically, I just want to have a list of Button class pointers, but for some reason it wont get past compiling. Thanks in advance for any help.

nullspace0
April 21st, 2002, 01:19 AM
Well, nevermind. I figured this one out on my own. I needed to use the "using std::list;" statement. After that, the compiler manages to get by the previous errors I was talking about. But, now it is giving me another error: "\screen.cpp(17) : error C2653: 'list<class Button *,class std::allocator<class Button *> >' : is not a class or namespace name"....what does this mean exactly? Thanks in advance.

Paul McKenzie
April 21st, 2002, 02:27 AM
You must have forgotten to #include <list> somewhere. Your solution to your previous problem is not the best -- you should have done this:

#include <list>
#include "Button.h" //my Button class header
class Screen
{
public:
//Stuff Cut Out
private:
std::list<Button*> pButtonList;
//More stuff cut
};



Note the use of std:: instead of the "using" clause. When you use "using", you are introducing a namespace into your header file. Reserve the "using" clause for .CPP files, not headers.

Regards,

Paul McKenzie