vector erase() problem

This is a discussion on vector erase() problem within the C++ Programming forums, part of the General Programming Boards category; havent been programming recently but school just finished so i got back to it, but im getta couple wierd errors ...

  1. #1
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227

    vector erase() problem

    havent been programming recently but school just finished so i got back to it, but im getta couple wierd errors that i cant straighten out

    i have this code:

    Code:
    P1_Values.push_back(deckValues[x]);
                deckValues.erase(x);


    and these errors:
    no matching function for call to ` std::vector<int, std::allocator<int> >::erase(int&)'

    error C:\Dev-Cpp\include\c++\3.3.1\bits\vector.tcc:105 candidates are: __gnu_cxx::__normal_iterator<_Tp*, std::vector<_Tp, _Alloc> >


    i went to the msdn site and looked for their documentation on the erase() function and the only difference between their sample code and mine is that they use an iterator and i use an integer. so i tried using the iterator but that and didnt work either.

    any ideas on why its not working?
    Keyboard Not Found! Press any key to continue. . .

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,650
    Try the iterator again. If you still need help, post some code.

    gg

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Code:
    // change:
      deckValues.erase(x);
    // to:
      deckValues.erase(deckValues.begin() + x);// begin_iterator + index_offset

  4. #4
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    guess that was the one thing i didnt try lucky
    thanks a lot lucky that worked
    Keyboard Not Found! Press any key to continue. . .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21