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. operator over loading problem?

operator over loading problem?

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++questionlounge
6 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.
  • Y Offline
    Y Offline
    york528
    wrote on last edited by
    #1

    lately when I use STL map as a parameter in a function I have a problem? such as:

    void func(const map<struct>& mapUsed)
    {
    map<struct>::iterator iterMap = mapUsed.begin()
    while(iterMap != mapUsed.end())
    {
    //do something
    }
    }

    The vs2008 report an error and when I use const_iterator to instead random iterator It's ok And I wanna know If STL use "const" overloading such as operator == ... If not ? How dose STL do? Thanks a lot! :doh:

    J 1 Reply Last reply
    0
    • Y york528

      lately when I use STL map as a parameter in a function I have a problem? such as:

      void func(const map<struct>& mapUsed)
      {
      map<struct>::iterator iterMap = mapUsed.begin()
      while(iterMap != mapUsed.end())
      {
      //do something
      }
      }

      The vs2008 report an error and when I use const_iterator to instead random iterator It's ok And I wanna know If STL use "const" overloading such as operator == ... If not ? How dose STL do? Thanks a lot! :doh:

      J Offline
      J Offline
      josda1000
      wrote on last edited by
      #2

      map<struct> should be more like map<int, int> or something. you're indexing one type of thing to another type of thing. you're not just making a vector of structs. even then, if you are making a map of int->structs, then the data type has to be used. the map must know how large of an allotment of memory it has to block off for each part of the map. hope that made sense...

      Y 1 Reply Last reply
      0
      • J josda1000

        map<struct> should be more like map<int, int> or something. you're indexing one type of thing to another type of thing. you're not just making a vector of structs. even then, if you are making a map of int->structs, then the data type has to be used. the map must know how large of an allotment of memory it has to block off for each part of the map. hope that made sense...

        Y Offline
        Y Offline
        york528
        wrote on last edited by
        #3

        Hi, I'm sorry that I made a mistake! what I mean is when I use STL::map or else Using iterator as a left value and a map&lt;X,Y&gt; as a parameter of a function as bellow

        void func(const map<X,Y> mapUsed)
        {
        map<X,Y>::iterator iterMap = mapUsed.begin(); //IDE report wrong here
        while(iterMap != mapUsed.end())
        {
        //do something
        }
        }

        mapUsed.begin() returned a const_iterator it dosen't match with iterator I was confusing that how dose mapUsed know itself is a const one and return const_iterator Did the IDE do it for us or STL used some other way? Thanks a lot!

        L 1 Reply Last reply
        0
        • Y york528

          Hi, I'm sorry that I made a mistake! what I mean is when I use STL::map or else Using iterator as a left value and a map&lt;X,Y&gt; as a parameter of a function as bellow

          void func(const map<X,Y> mapUsed)
          {
          map<X,Y>::iterator iterMap = mapUsed.begin(); //IDE report wrong here
          while(iterMap != mapUsed.end())
          {
          //do something
          }
          }

          mapUsed.begin() returned a const_iterator it dosen't match with iterator I was confusing that how dose mapUsed know itself is a const one and return const_iterator Did the IDE do it for us or STL used some other way? Thanks a lot!

          L Offline
          L Offline
          Lim Bio Liong
          wrote on last edited by
          #4

          >> I was confusing that how dose mapUsed know itself is a const one and return const_iterator... It depends on how "mapUsed" is declared for the function func : void func(const map<X,Y> mapUsed) since "mapUsed" is declared as a const, the compiler naturally uses the const_iterator. - Bio.

          Y 1 Reply Last reply
          0
          • L Lim Bio Liong

            >> I was confusing that how dose mapUsed know itself is a const one and return const_iterator... It depends on how "mapUsed" is declared for the function func : void func(const map<X,Y> mapUsed) since "mapUsed" is declared as a const, the compiler naturally uses the const_iterator. - Bio.

            Y Offline
            Y Offline
            york528
            wrote on last edited by
            #5

            I thought it is about the program language Now I know the complier do this, Thank you ;P

            L 1 Reply Last reply
            0
            • Y york528

              I thought it is about the program language Now I know the complier do this, Thank you ;P

              L Offline
              L Offline
              Lim Bio Liong
              wrote on last edited by
              #6

              Most welcome york528   :)

              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