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. typedef in templates?

typedef in templates?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcsswpfquestion
8 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.
  • N Offline
    N Offline
    N O R B E R T
    wrote on last edited by
    #1

    I'm writing a class which is more or less a STL map with a few enhancements, e.g. sending of update notifications. To still have STL like access to the map, I forward the map iterators in my class with public typedefs. The problem is, those typedefs seem to be missing a semicolon where there is definitely none missing; #include template class Repository { private: typedef std::map ReposMap; public: typedef ReposMap::iterator iterator; //line 14 typedef ReposMap::const_iterator const_iterator; //line 15 public: Repository() { } ~Repository() { } //[...] some other functions ... private: ReposMap m_objects; }; MSVC8 gives the following error msgs compiling this code:

    Error 2: error C2146: syntax error : missing ';' before identifier 'iterator' 14
    Error 3: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 14

    and the same error msgs again for line 15 before 'const_iterator' I was wondering what the error could be in that few lines of code. Typedefs should be able to work with template parameters, so there shouldn't be an problem, should it? I'm trying to compile this and some other versions of the same problem for two days now, but I don't have an idea, what could cause the problem, so I'd appreciate any suggestions. thanks in advance, Norbert

    N 1 Reply Last reply
    0
    • N N O R B E R T

      I'm writing a class which is more or less a STL map with a few enhancements, e.g. sending of update notifications. To still have STL like access to the map, I forward the map iterators in my class with public typedefs. The problem is, those typedefs seem to be missing a semicolon where there is definitely none missing; #include template class Repository { private: typedef std::map ReposMap; public: typedef ReposMap::iterator iterator; //line 14 typedef ReposMap::const_iterator const_iterator; //line 15 public: Repository() { } ~Repository() { } //[...] some other functions ... private: ReposMap m_objects; }; MSVC8 gives the following error msgs compiling this code:

      Error 2: error C2146: syntax error : missing ';' before identifier 'iterator' 14
      Error 3: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 14

      and the same error msgs again for line 15 before 'const_iterator' I was wondering what the error could be in that few lines of code. Typedefs should be able to work with template parameters, so there shouldn't be an problem, should it? I'm trying to compile this and some other versions of the same problem for two days now, but I don't have an idea, what could cause the problem, so I'd appreciate any suggestions. thanks in advance, Norbert

      N Offline
      N Offline
      N O R B E R T
      wrote on last edited by
      #2

      sorry, it seems my <'s have been removed. Here should be the corrected version of the code: template <typename K, typename V> class Repository { private: typedef std::map<K, V> ReposMap; public: typedef ReposMap::iterator iterator; typedef ReposMap::const_iterator const_iterator; public: Repository() { } ~Repository() { } private: ReposMap m_objects; };

      P 1 Reply Last reply
      0
      • N N O R B E R T

        sorry, it seems my <'s have been removed. Here should be the corrected version of the code: template <typename K, typename V> class Repository { private: typedef std::map<K, V> ReposMap; public: typedef ReposMap::iterator iterator; typedef ReposMap::const_iterator const_iterator; public: Repository() { } ~Repository() { } private: ReposMap m_objects; };

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #3

        N-O-R-B-E-R-T wrote:

        public: typedef ReposMap::iterator iterator; typedef ReposMap::const_iterator const_iterator;

        Modify this to,

        typename ReposMap::iterator iterator;
        typename ReposMap::const_iterator const_iterator;

        See MSDN documentation for warning C4346.

        Prasad Notifier using ATL | Operator new[],delete[][^]

        N S 2 Replies Last reply
        0
        • P prasad_som

          N-O-R-B-E-R-T wrote:

          public: typedef ReposMap::iterator iterator; typedef ReposMap::const_iterator const_iterator;

          Modify this to,

          typename ReposMap::iterator iterator;
          typename ReposMap::const_iterator const_iterator;

          See MSDN documentation for warning C4346.

          Prasad Notifier using ATL | Operator new[],delete[][^]

          N Offline
          N Offline
          N O R B E R T
          wrote on last edited by
          #4

          I've had the warnings supressed, and I forgot about that. I'm sorry for posting without reading all errors AND warnings before. Thanks for your fast help. Norbert

          P 2 Replies Last reply
          0
          • N N O R B E R T

            I've had the warnings supressed, and I forgot about that. I'm sorry for posting without reading all errors AND warnings before. Thanks for your fast help. Norbert

            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #5

            N-O-R-B-E-R-T wrote:

            I've had the warnings supressed, and I forgot about that

            You should not ignore warning at all ! :)

            Prasad Notifier using ATL | Operator new[],delete[][^]

            1 Reply Last reply
            0
            • P prasad_som

              N-O-R-B-E-R-T wrote:

              public: typedef ReposMap::iterator iterator; typedef ReposMap::const_iterator const_iterator;

              Modify this to,

              typename ReposMap::iterator iterator;
              typename ReposMap::const_iterator const_iterator;

              See MSDN documentation for warning C4346.

              Prasad Notifier using ATL | Operator new[],delete[][^]

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              prasad_som wrote:

              Modify this to, typename ReposMap::iterator iterator;typename ReposMap::const_iterator const_iterator;

              I assume you mean this:

              typedef typename ReposMap::iterator iterator;
              typedef typename ReposMap::const_iterator const_iterator;

              Steve

              P 1 Reply Last reply
              0
              • S Stephen Hewitt

                prasad_som wrote:

                Modify this to, typename ReposMap::iterator iterator;typename ReposMap::const_iterator const_iterator;

                I assume you mean this:

                typedef typename ReposMap::iterator iterator;
                typedef typename ReposMap::const_iterator const_iterator;

                Steve

                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #7

                Stephen Hewitt wrote:

                I assume you mean this: typedef typename ReposMap::iterator iterator;typedef typename ReposMap::const_iterator const_iterator;

                Yes. :)

                Prasad Notifier using ATL | Operator new[],delete[][^]

                1 Reply Last reply
                0
                • N N O R B E R T

                  I've had the warnings supressed, and I forgot about that. I'm sorry for posting without reading all errors AND warnings before. Thanks for your fast help. Norbert

                  P Offline
                  P Offline
                  prasad_som
                  wrote on last edited by
                  #8

                  Have a look at reply below, posted by Stephan.

                  Prasad Notifier using ATL | Operator new[],delete[][^]

                  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