In a function if I have a vector passed as a parameter, and I have an object in the function which was created with automatic storage duration, if that object is pushed onto the vector(parameter), will that object not be destroyed until the vector is?
Automatic storage duration interacting with other objects
152 views Asked by AudioBubble At
2
You cannot "push that object" onto a vector. You're pushing a copy of the object onto the vector (unless you have something arcane like a vector of reference wrappers). So everything is fine.
(There are of course other ways to shoot yourself in the foot with poorly designed classes that don't properly manage ownership of further, dynamic objects, but that's a general problem not specific to your question.)