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. ATL / WTL / STL
  4. What overloaded member function called in if(iterator)

What overloaded member function called in if(iterator)

Scheduled Pinned Locked Moved ATL / WTL / STL
c++graphics
5 Posts 4 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.
  • D Offline
    D Offline
    DevendraC
    wrote on last edited by
    #1

    Hi, Can anyone tell me which overloaded function is called, below in Line 2: vector::iterator it = nArray.begin(); // Line 1 if(it) //What overloaded function called here // Line 2 .................. As I know in this case overloaded (operator void *) function is called, But I d'nt find any such overloaded function in STL iterator class. Regards Devendra Chandola

    J 1 Reply Last reply
    0
    • D DevendraC

      Hi, Can anyone tell me which overloaded function is called, below in Line 2: vector::iterator it = nArray.begin(); // Line 1 if(it) //What overloaded function called here // Line 2 .................. As I know in this case overloaded (operator void *) function is called, But I d'nt find any such overloaded function in STL iterator class. Regards Devendra Chandola

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      As you point out, there's no official procedure in the STL specification to test an iterator in such a way. What's happening is that, for vector alone, and for your particular compiler, vector::iterator happens to be an actual pointer, so the expression makes sense --it tests whether the pointer is non-null, which makes little sense in the given context. This is non-portable and you are not guaranteed that the test yield any significative result. Most likely what's intended is the following:

      if(it!=nArray.end()){
      ...
      }

      Hope this helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!

      D 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        As you point out, there's no official procedure in the STL specification to test an iterator in such a way. What's happening is that, for vector alone, and for your particular compiler, vector::iterator happens to be an actual pointer, so the expression makes sense --it tests whether the pointer is non-null, which makes little sense in the given context. This is non-portable and you are not guaranteed that the test yield any significative result. Most likely what's intended is the following:

        if(it!=nArray.end()){
        ...
        }

        Hope this helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!

        D Offline
        D Offline
        DevendraC
        wrote on last edited by
        #3

        Hi Joaquín, Thanks for suggestion I still want to know which overloaded function of iterator is called when we write: if(iterator) Regards Devendra Chandola

        G M 2 Replies Last reply
        0
        • D DevendraC

          Hi Joaquín, Thanks for suggestion I still want to know which overloaded function of iterator is called when we write: if(iterator) Regards Devendra Chandola

          G Offline
          G Offline
          guypremont
          wrote on last edited by
          #4

          There is no general answer to your question. Actually, you should not even ask the question because the "if (iterator)" should not generally compile. However, in your case, the magic of typedef's probably makes it valid and equivalent to "if (pointer)". Also, the "suggestion" to do "if ( iterator == container.end() )" is NOT a suggestion: it is the only valid way to check for iterator validity. my 2 cents... Guy Prémont

          1 Reply Last reply
          0
          • D DevendraC

            Hi Joaquín, Thanks for suggestion I still want to know which overloaded function of iterator is called when we write: if(iterator) Regards Devendra Chandola

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            DevendraC wrote: I still want to know which overloaded function of iterator is called when we write: if(iterator) Set a breakpoint on that if statement, and step into the line (F11) and you'll see. --Mike-- LINKS~! Ericahist updated! | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ Strange things are afoot at the U+004B U+20DD

            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