c++, erasing something from a vector?

  • Bozebo
  • Expert
  • Expert
  • User avatar
  • Posts: 709
  • Loc: 404

Post 3+ Months Ago

Hi, I have a vector that gets populated by instances. Though, it seems to be making the erase() functionality of vectors unusable :S
Here is what I am talking about:
Code: [ Select ]
 
class Ctest;
vector <Ctest> testObjects;
class Ctest{
  int id;
  int something1,something2;
  float whatever;
  public:
    Ctest(int setId){
      id = setId;
    }
    ~Ctest();
    someMethod();
    anotherMethod(){
      //... stuff
      //... more stuff
 
      testObjects.erase(id);
    }
};
 
int main(){
  testObjects.push_back(testObjects.size());
  testObjects.push_back(testObjects.size());
  testObjects.push_back(testObjects.size());
  testObjects[1].anotherMethod();
...
 
  1.  
  2. class Ctest;
  3. vector <Ctest> testObjects;
  4. class Ctest{
  5.   int id;
  6.   int something1,something2;
  7.   float whatever;
  8.   public:
  9.     Ctest(int setId){
  10.       id = setId;
  11.     }
  12.     ~Ctest();
  13.     someMethod();
  14.     anotherMethod(){
  15.       //... stuff
  16.       //... more stuff
  17.  
  18.       testObjects.erase(id);
  19.     }
  20. };
  21.  
  22. int main(){
  23.   testObjects.push_back(testObjects.size());
  24.   testObjects.push_back(testObjects.size());
  25.   testObjects.push_back(testObjects.size());
  26.   testObjects[1].anotherMethod();
  27. ...
  28.  


Now... when I try to compile (my actual code, not the example above) with gcc I get an error:
Quote:
error: no matching function for call to 'std::vector<CenemyBullet,std::allocator<CenemyBullet>>::erase(u16&)'


What I think it is stupidly trying to do is find the erase member in the class I have defined... what is up with that? Is that normal or have I done something stupid (defining the vector globally between definitions for the class?).
If that is normal... doesn't that make vectors unusable for objects?

Download my full source. The code in question is within main.cpp, and yes I know there are a lot of other issues in the code ^_^ it's a WIP, ill get round to cleaning it. Unless of course those issues caused that problem.

Oh, I am compiling for the GBA, using devkit advanced. So you most likely won't be able to compile it straight off if you need to do so. If you want you can download the full thing (over 21MB).

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 72 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.