I want to store 10 Obj
object in objList
, but i don't know when is appropriate use delete
in this case. If i use delete Obj;
in the line where i note in below code, will the Obj
still be stored in objList
?
struct Obj {
int u;
int v;
};
vector<Obj> objList;
int main() {
for(int i = 0; i < 10; i++) {
Obj *obj = new Obj();
obj->u = i;
obj->v = i + 1;
objList.push_back(*obj);
// Should i use "delete Obj;" here?
}
}
See Question&Answers more detail:os