c + +, borrar algo de un vector?

  • Bozebo
  • Expert
  • Expert
  • Avatar de Usuario
  • Registrado: Feb 15, 2006
  • Mensajes: 709
  • Loc: 404
  • Status: Offline

Nota Agosto 7th, 2009, 6:44 am

Hola, tengo un vector que se pobladas por los casos. Sin embargo, parece estar haciendo el borrado () la funcionalidad de los vectores inutilizable: S
Esto es lo que estoy hablando y #058;
Código: [ 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.  


Ahora...cuando intento compilar (no el código actual, el ejemplo anterior) con gcc me da un error:
Quote:
error: no existe la función de contrapartida para llamar a std:: vector <CenemyBullet, std:: asignador <CenemyBullet>>:: erase (Sub-16 &)


Lo que creo que es estúpidamente tratando de hacer es encontrar el miembro de borrar en la clase que he definido...¿Qué hay con eso? ¿Es eso normal o he hecho algo estúpido (la definición del vector a nivel mundial entre las definiciones de la clase?).
Si eso es normal...no vectores que hacen inservible para los objetos?

Descargar mi fuente completo . El código en cuestión está dentro de main.cpp, y sí sé que hay un montón de otras cuestiones en el código de ^ _ ^ Es un WIP, malos eludir a limpiarlo. A menos, por supuesto, los problemas causados a ese problema.

¡Oh, estoy compilando para la GBA, utilizando SDK de avanzada. Así que muy probablemente no será capaz de compilar directamente hacia afuera, si es necesario hacerlo. Si lo desea puede descargar el cosa completa (más de 21MB).
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Agosto 7th, 2009, 6:44 am

Publicar Información

  • Total de mensajes en este tema: 1 mensaje
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 237 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC