|
-
April 21st, 2002, 01:00 AM
#1
How come I get compiler errors when using the STL inside a class?
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.
-
April 21st, 2002, 01:19 AM
#2
Re: How come I get compiler errors when using the STL inside a class?
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.
-
April 21st, 2002, 02:27 AM
#3
Re: How come I get compiler errors when using the STL inside a class?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|