CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Aug 2003
    Posts
    30

    Problems using the STL list template

    Hello all,

    I'm trying to use the STL list template class in some code of mine and I get weird errors, or at least they look weird to me. I'm properly including the list header at the beginning of my file (#include <list>) and when I try to declare a list with "std::list<mytype> mylist;" the compiler is telling me that list isn't in the std namespace.

    I am using Visual C++ 7.0. Am I doing something stupid or is this a known bug?

    Thanks in advance,
    Maxime

  2. #2
    Join Date
    May 2000
    Location
    Scotland, Livingston.
    Posts
    728
    That looks as if it should work fine.

    What is the exact error message?

    What is the definition of mytype?

    Can you post the code?
    Dave Mclelland.

  3. #3
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Lightbulb Re: Problems using the STL list template

    Originally posted by mux

    with "std::list<mytype> mylist;" the compiler is telling me that list isn't in the std namespace.
    Did you forget to put:

    Code:
    using namespace std;
    At the beginning of the header where you declare your STL based objects (vector/list/whatever..)?

    Sid

  4. #4
    Join Date
    Aug 2003
    Posts
    30
    Originally posted by Dave McLelland
    That looks as if it should work fine.

    What is the exact error message?

    What is the definition of mytype?

    Can you post the code?
    The exact error message is "'list' : is not a member of 'std'".

    mytype is a rdv_t, which is a typedef on a struct.

    I'm sorry, I can't post the code here, and I'm really sorry to say this, being an opensource developper the night... But the day I have to do VC++ for my employer and can't disclose the code :-(.

    The code looks like this :

    #include <list>

    // Other headers here.

    typedef struct CRdv_t {
    // Some stuff here.
    } rdv_t;

    // Various methods here.

    SomeType
    SomeObject::SomeMethod(SomeParameters) {
    // Other variables definition.
    std::list<rdv_t> mylist;

    // Body of the method.
    }

    It chokes on the std::list<rdv_t> mylist; as described above.

    The code looks really correct to me, I'm puzzled :-(.

    Cheers,
    Maxime

  5. #5
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205
    Originally posted by mux
    The exact error message is "'list' : is not a member of 'std'".

    mytype is a rdv_t, which is a typedef on a struct.

    I'm sorry, I can't post the code here, and I'm really sorry to say this, being an opensource developper the night... But the day I have to do VC++ for my employer and can't disclose the code :-(.

    The code looks like this :

    #include <list>

    // Other headers here.

    typedef struct CRdv_t {
    // Some stuff here.
    } rdv_t;

    // Various methods here.

    SomeType
    SomeObject::SomeMethod(SomeParameters) {
    // Other variables definition.
    std::list<rdv_t> mylist;

    // Body of the method.
    }

    It chokes on the std::list<rdv_t> mylist; as described above.

    The code looks really correct to me, I'm puzzled :-(.

    Cheers,
    Maxime
    Hate to repeat myself! :-)

    I don't see this line:

    Code:
    using namespace std;
    Please put it, and then check!

  6. #6
    Join Date
    Aug 2003
    Posts
    30
    Originally posted by Siddhartha
    Hate to repeat myself! :-)

    I don't see this line:

    Code:
    using namespace std;
    Please put it, and then check!
    As far as I can tell, this line is absolutely not needed since I'm not trying to access the list template as list but as std::list. Besides, I already said in this thread that putting this line didn't help at all.

    Cheers,
    Maxime

  7. #7
    Join Date
    May 2000
    Location
    Scotland, Livingston.
    Posts
    728
    That should work (works here).
    Do a preprocessed listing to a file and see what is actually being produced.

    Can you post the actual code from the function declaration to the line after the std::list?
    Dave Mclelland.

  8. #8
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    Originally posted by Siddhartha
    Hate to repeat myself! :-)

    I don't see this line:

    Code:
    using namespace std;
    Please put it, and then check!
    Since he uses the qualified name std::list, he doesn't have to use using namespace std.

    To mux: Your problem must be elsewhere. Are any of your class declarations not followed by a semicolon ? Are you inside of another namespace ?

    The following code compiles just fine (to show that what you posted can't be the problem):
    Code:
    #include <list>
    
    // Other headers here.
    
    typedef struct CRdv_t {
      int i;
    } rdv_t;
    
    // Various methods here.
    
    class CSomeObject
    {
    public:
      int SomeMethod(int a);
    };
    
    int CSomeObject::SomeMethod(int a) {
    // Other variables definition.
    std::list<rdv_t> mylist;
    
    // Body of the method.
      return 0;
    }
    
    int main()
    {
      CSomeObject c;
      return 0;
    }
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  9. #9
    Join Date
    Aug 2003
    Posts
    30
    Originally posted by Dave McLelland
    That should work (works here).
    Do a preprocessed listing to a file and see what is actually being produced.

    Can you post the actual code from the function declaration to the line after the std::list?
    Here it is :

    void
    CCalView::CalcRdvRectList(CList<CRdv, CRdv> &RdvList, CList<CRect, CRect> &RdvRectList)
    {
    std::list<rdv_t> RdvCtrlList;
    std::list<std::list<rdv_t>> AllConflicts;
    std::list<rdv_t> ConflictsList;
    POSITION pos;
    CWnd * pRdvCtrl = NULL;
    CRdv Rdv;
    rdv_t rdv;

    // Body of the method here.
    }

    It chokes at the very first std::list usage with the error message given in previous posts. I have no idea how to get a preprocessed file in Visual C++. Can you enlighten me?

    Cheers,
    Maxime

  10. #10
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    std::list<std::list<rdv_t>> AllConflicts;
    You are missing a space between the two ">". It should be:
    Code:
     std::list<std::list<rdv_t> > AllConflicts;
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  11. #11
    Join Date
    May 2000
    Location
    Scotland, Livingston.
    Posts
    728
    right click on the source file in the solution explorer window.
    From the C/C++ entry select preprocessor.
    Select either of the options from "Generate preprocessed file".
    The resultant file will have the .i extension.

    Search this for your CalcRdvRectList and see what it says.
    Dave Mclelland.

  12. #12
    Join Date
    Aug 2003
    Posts
    30
    Originally posted by Yves M
    You are missing a space between the two ">". It should be:
    Code:
     std::list<std::list<rdv_t> > AllConflicts;
    Ok, I added it, thanks. But the compiler still errors. It's actually choking before this line, at the first usage of std::list. I don't think that I'm already inside some namespace since I don't see any other "using namespace" declaration.

    Cheers,
    Maxime

  13. #13
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    Are you including any list.h inside of this file or the other headers that are included ?
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  14. #14
    Join Date
    Aug 2003
    Posts
    30
    Originally posted by Yves M
    Are you including any list.h inside of this file or the other headers that are included ?
    Yes, I am, or actually I was :-). I moved the "#include <list>" after the other #include directives and it's now working. There must have been something in those headers which was confusing stuff. Thanks a bunch for your help and the other members' help!

    Cheers,
    Maxime

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