Hi I'm trying to do this (and it seem works):
std::vector<Light*> light; // it's a vector of pointer to Light
Light* l;
l = new Light[10];
light.push_back(l);
delete [] l; //delete is necessary
std::vector<Light*> light; // it's a vector of pointer to Light
Light* l;
l = new Light[10];
light.push_back(l);
delete [] l; //delete is necessary
To copy to clipboard, switch view to plain text mode
I I understand fine, this is a vector of Light with only one element(a pointer) that point to an array of 10 Light. Is it this?
Otherwise:
std::vector<Light*> light; // it's a vector of pointer to Light
Light* l;
l = new Light;
for (int i=0; < 10< i++)
light.push_back(l);
delete [] l; //delete is necessary
std::vector<Light*> light; // it's a vector of pointer to Light
Light* l;
l = new Light;
for (int i=0; < 10< i++)
light.push_back(l);
delete [] l; //delete is necessary
To copy to clipboard, switch view to plain text mode
Here I've a vecotr of 10 elements (pointer) that each one point to a Light;
std::vector<Light> light;
for (int i=0; <10; i++)
light.push_back(Light());
std::vector<Light> light;
for (int i=0; <10; i++)
light.push_back(Light());
To copy to clipboard, switch view to plain text mode
I prefer the last....
Wich is better? Thanks
Bookmarks