I have a vector<some_struct&> array in my code, and whenever I want to add some object to my vector I use array.push_back(*new some_struct). now I’m wondering if I should delete every object in my array before clearing my array (using delete &array[i]) or not?
I have a vector<some_struct&> array in my code, and whenever I want to add
Share
vector<some_struct&> arrayis invalid, period.The type (or types) with which you instantiate a Standard Library container must be object types. A reference type (like
some_struct&) is not an object type.By definition, “containers are objects that store other objects” (from §23.1/1 in both C++03 and C++0x). References are not objects.
The behavior is undefined if you instantiate a container with a type that does not meet the requirements that the container imposes: your code may or may not compile and if it does compile, who knows what the result will be; anything could happen..