Instances in vector(efficient way)

Hi, i am trying to make a vector that contains 5 instances(Bomba1, Bomba2, Bomba3, Bomba4, Bomba5)and this is what i got.

"Personajes->Ingresar_Bomba" put the intstance inside the vector

//
vector<CBomba*> vec_bombas;
void Ingresar_Bomba(CBomba *s){
if(vec_bombas.size() < 5){
vec_bombas.push_back(s);
}
}
//

Bomba1 = new CBomba(1,0);
Bomba2 = new CBomba(1,1);
Bomba3 = new CBomba(1,2);
Bomba4 = new CBomba(1,3);
Bomba5 = new CBomba(1,4);
Personaje->Ingresar_Bomba(Bomba1);
Personaje->Ingresar_Bomba(Bomba2);
Personaje->Ingresar_Bomba(Bomba3);
Personaje->Ingresar_Bomba(Bomba4);
Personaje->Ingresar_Bomba(Bomba5);

it do what its supposed to do but i guess there is a better way to do it.
im using c++.net
sorry if something is wrongly spelled my english is not very good.
Last edited on
The feature you're looking for is called "List Initialization": http://en.cppreference.com/w/cpp/language/list_initialization

At least in C++ it is, C++\CLI is a completely different language and one that I am not personally familiar with. What you have here actually won't compile in C++ even if one were to take care of the missing class definition.
Topic archived. No new replies allowed.