CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2002
    Posts
    5

    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.


  2. #2
    Join Date
    Apr 2002
    Posts
    5

    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.


  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    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
  •  





Click Here to Expand Forum to Full Width

Featured