samedi 5 octobre 2019

function to remove object from vector passing in a pointer

i have two vectors. one is a (1) vector which contains all objects im using and works with that. the other vector is a (2) vector which after a function adds an object from (1) into (2). once this happens i want to remove the object from (1). the problem is that the function i made to remove it takes in a object * obj. the actual object still has pointers pointing to it and i dont want to fully wipe the obj, just remove it from (1). any help would be appreciated.

`

void removeObject(const Object * obj) {
        int index;
        for (int i = 0; i < size(); i++) {
            if (obj == & objectVector[i] ) {
                index = i;
            }
        }
        objectVector.erase(objectVector.begin() + index);
    }

`

im sure this is the problem because when i dont comment out the line using this function i get a sigtrap error

Aucun commentaire:

Enregistrer un commentaire