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. Vector Iterator Incompatible

Vector Iterator Incompatible

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestion
3 Posts 2 Posters 3 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.
  • M Offline
    M Offline
    mjackson11
    wrote on last edited by
    #1

    I am getting a run time error with the code below. Trying to use a static iterator to reduce the number of calls to search a vector. This is a method of a class that contains a vector of curves (so _vector is part of the class.) It runs correctly the first few times called, but the first time the static iterator doesn't point to the correct curve and _vector should be searched, I get a runtime error "Incompatible Vector Iterators" calling the == operator. I can't really tell what the error is. If it is a const versus non-const or it is creating copies of the vector somewhere. Is there a better way to do this? Thanks Mark

    bool findpt(pt_tag<_Ty>* s)
    {
    if (_vector.empty())
    return false;

    static vector< curve<\_Ty> >::iterator i = \_vector.end();
    
    if (i == \_vector.end())  <-- RUN TIME ERROR HERE
    
        i = std::lower\_bound( \_vector.begin(), \_vector.end(), s->\_dtEffDate );
    else {
        if ((i.\_Ptr->getdate() != s->\_dtEffDate))
            i = std::lower\_bound( \_vector.begin(), \_vector.end(), s->\_dtEffDate );
    }
    
    if ((i == \_vector.end()) || (s->\_dtEffDate != (\*i).\_date))
        return false;
    
    cpoint<\_Ty> c;
    
    c.setdate( s->\_dtFwdDate );
    
    if (i.\_Ptr->interpolate( &c ) == true) {
        s->\_valid = true;
        s->\_value = c.getvalue();
        return true;
    }
    return false;
    

    }

    C 1 Reply Last reply
    0
    • M mjackson11

      I am getting a run time error with the code below. Trying to use a static iterator to reduce the number of calls to search a vector. This is a method of a class that contains a vector of curves (so _vector is part of the class.) It runs correctly the first few times called, but the first time the static iterator doesn't point to the correct curve and _vector should be searched, I get a runtime error "Incompatible Vector Iterators" calling the == operator. I can't really tell what the error is. If it is a const versus non-const or it is creating copies of the vector somewhere. Is there a better way to do this? Thanks Mark

      bool findpt(pt_tag<_Ty>* s)
      {
      if (_vector.empty())
      return false;

      static vector< curve<\_Ty> >::iterator i = \_vector.end();
      
      if (i == \_vector.end())  <-- RUN TIME ERROR HERE
      
          i = std::lower\_bound( \_vector.begin(), \_vector.end(), s->\_dtEffDate );
      else {
          if ((i.\_Ptr->getdate() != s->\_dtEffDate))
              i = std::lower\_bound( \_vector.begin(), \_vector.end(), s->\_dtEffDate );
      }
      
      if ((i == \_vector.end()) || (s->\_dtEffDate != (\*i).\_date))
          return false;
      
      cpoint<\_Ty> c;
      
      c.setdate( s->\_dtFwdDate );
      
      if (i.\_Ptr->interpolate( &c ) == true) {
          s->\_valid = true;
          s->\_value = c.getvalue();
          return true;
      }
      return false;
      

      }

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      are you modifying the vector between calls to this function? if so, that might (will, probably) invalidate 'i'.

      image processing toolkits | batch image processing

      M 1 Reply Last reply
      0
      • C Chris Losinger

        are you modifying the vector between calls to this function? if so, that might (will, probably) invalidate 'i'.

        image processing toolkits | batch image processing

        M Offline
        M Offline
        mjackson11
        wrote on last edited by
        #3

        I am canning this routine as the vector may end up being modified. Thx for the input.

        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