0

So the person here had the same dilemma, and discovered that the vector erase function requires an iterator. I was able to recreate the best answer's example solution in an isolated test environment with the same libraries as my main console RPG I'm making.

However, when I implement the test code, with no discernable differences (that I can see), I get the following errors:

Here are the errors:

conversion from `__gnu_cxx::__normal_iterator<weapon*, std::vector<weapon, std::allocator<weapon> > >' to non-scalar type `__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >' requested 

no matching function for call to `std::vector<weapon, std::allocator<weapon> >::erase(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >&)' 

Here's the source code for the "bad" method:

std::vector<int>::iterator i = std::find(myWeapons.begin(), myWeapons.end(), 2);
myWeapons.erase(i);

And here's the example code from the above referenced thread.

#include <vector>
#include <algorithm>

int main()
{
    std::vector<int> v;

    v.push_back(1);
    v.push_back(2);
    v.push_back(3);

    std::vector<int>::iterator i = std::find(v.begin(), v.end(), 2);
    v.erase(i);
}

If it helps, here are the total libraries in use - in both my working test environment and RPG.

#include <cstdlib>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
#include <conio.h>

It's probably something obvious - but I'm just not seeing it. Please let me know if anything else would be helpful. My guess is that in the example code, the vector is made up of ints, where as in the myWeapons vector, it is made up of Structs. Thank you to anyone able to help.

I expected to be able to use the erase member function of vector to be able to isolate, and remove specific vector elements. Worked fine in test environment, got a "no matching function" error when transferred to actual project.

273K
  • 29,503
  • 10
  • 41
  • 64
Darthbamf
  • 9
  • 2

0 Answers0