include <typeinfo>
vector<Console*> consoles;
Console* sony = new Sony();
cout << typeid(sony).name() << endl; // typeid name == 4Sony
consoles.push_back(sony);
cout << typeid(*consoles.back()).name() << endl; // typeid name == 7Console
Console* microsoft = new Microsoft();
consoles.push_back(microsoft);//the same happens with microsoft consoles
this is basically what I'm trying to do:
for(int i = 0; i < consoles.size(); i++){
if(typeid(*consoles[i]).name() == typeid(Sony).name()){
//cout << "it's a sony console" << endl;
}
}
I can't do this because the typeid name of the console changes after I add it to the vector, so is there a way to make the typeid name of the console to stay the same after adding it to the vector?