I'm relatively new to C++ (coming from Java) and I've got a little problem regarding lifetime of objects. My situation is like this: I'm having a class A in which I'm trying to add elements to an vector in class B. This vector itself shall hold objects (not pointers) of class C. However, since the objects are created in class As function, the are supposed to be deleted after the end of this function. So when I try to access these objects it gives me weird results. I'm currently passing the created objects as call by reference (using references instead of pointers). My question is, what can I do / use to have the vectors elements not deleted but saved for later use?
Aucun commentaire:
Enregistrer un commentaire