Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using STL iterator as class member variable [modified]

Using STL iterator as class member variable [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anton112
    wrote on last edited by
    #1

    I'm trying to implement a "MFC CList look-alike" wrapper on top of the STL list using MS Visual C++ 2005 Express. The implementation of the iteration methods begin-next-prev-end requires a storage of the position in the class like this: #include template< class TYPE> class CList { protected: std::list< TYPE >::iterator pos; ... But it doesn't work... I get these compiler errors: warning C4346: 'std::list< TYPE >::iterator' : dependent name is not a type error C2146: syntax error : missing ';' before identifier 'pos' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int I don't quite understand the errors. Using the same declaration (std::list< TYPE >::iterator p) in a member function, I don't get any errors at all from the compiler. Why am I not allowed to declare this iterator (pos) as a member in the class? Hope someone can help? -- modified at 11:45 Tuesday 5th June, 2007 -- modified at 11:46 Tuesday 5th June, 2007

    Anton112

    D A 2 Replies Last reply
    0
    • A Anton112

      I'm trying to implement a "MFC CList look-alike" wrapper on top of the STL list using MS Visual C++ 2005 Express. The implementation of the iteration methods begin-next-prev-end requires a storage of the position in the class like this: #include template< class TYPE> class CList { protected: std::list< TYPE >::iterator pos; ... But it doesn't work... I get these compiler errors: warning C4346: 'std::list< TYPE >::iterator' : dependent name is not a type error C2146: syntax error : missing ';' before identifier 'pos' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int I don't quite understand the errors. Using the same declaration (std::list< TYPE >::iterator p) in a member function, I don't get any errors at all from the compiler. Why am I not allowed to declare this iterator (pos) as a member in the class? Hope someone can help? -- modified at 11:45 Tuesday 5th June, 2007 -- modified at 11:46 Tuesday 5th June, 2007

      Anton112

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Interesting, as your code snippet compiles fine with VS6.

      template<class T>
      class CList
      {
      protected:
      std::list<T>::iterator pos;
      };

      I'd guess that it has to do with VS2005 being more C++ compliant. See here.


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      A 1 Reply Last reply
      0
      • D David Crow

        Interesting, as your code snippet compiles fine with VS6.

        template<class T>
        class CList
        {
        protected:
        std::list<T>::iterator pos;
        };

        I'd guess that it has to do with VS2005 being more C++ compliant. See here.


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        A Offline
        A Offline
        Anton112
        wrote on last edited by
        #3

        Well, I have to admit that I don't know anything about compilers in that sense. Hence, I don't know anything about differences between specific compilers. In fact, years agy I tried to be a Windows developer, but it is years ago...

        Anton112

        1 Reply Last reply
        0
        • A Anton112

          I'm trying to implement a "MFC CList look-alike" wrapper on top of the STL list using MS Visual C++ 2005 Express. The implementation of the iteration methods begin-next-prev-end requires a storage of the position in the class like this: #include template< class TYPE> class CList { protected: std::list< TYPE >::iterator pos; ... But it doesn't work... I get these compiler errors: warning C4346: 'std::list< TYPE >::iterator' : dependent name is not a type error C2146: syntax error : missing ';' before identifier 'pos' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int I don't quite understand the errors. Using the same declaration (std::list< TYPE >::iterator p) in a member function, I don't get any errors at all from the compiler. Why am I not allowed to declare this iterator (pos) as a member in the class? Hope someone can help? -- modified at 11:45 Tuesday 5th June, 2007 -- modified at 11:46 Tuesday 5th June, 2007

          Anton112

          A Offline
          A Offline
          Arman S
          wrote on last edited by
          #4

          iterator cannot be deduced as a type by the compiler. To make it (compiler) think so, put typename in front of its declaration;

          template<class T>
          class CList{
          protected:
          typename std::list<T>::iterator pos;
          };

          -- ===== Arman

          A 1 Reply Last reply
          0
          • A Arman S

            iterator cannot be deduced as a type by the compiler. To make it (compiler) think so, put typename in front of its declaration;

            template<class T>
            class CList{
            protected:
            typename std::list<T>::iterator pos;
            };

            -- ===== Arman

            A Offline
            A Offline
            Anton112
            wrote on last edited by
            #5

            Thanks, Arman You gave me my answer...

            Anton112

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups