allocating structs within STL vectors
Hi. I have a question related to memory allocation within STL vectors. I wonder if the way I am allocating memory is correct and if de-allocation is being handled.
I am trying to use a vector of an object of my creation. There are pointers within the struct than need to be allocated. A simple example of what I'm trying to do follows:
Code:
struct my_struct
{
double *xyz;
}
vector<my_struct> my_vector;
my_struct ms;
ms.xyz = new double[xyz_size];
my_vector.push_back(ms);
Is this correct? I always thought you had to have a delete for every new. But in this case, I'm relying on the vector clean-up to deallocate the memory for double* xyz
thanks