How can I solve this? I want to execute proper method something. Is there any way to solve this? I want to execute method something in one loop.
class Base
{
public:
void something() {}
};
class Child : public Base
{
public:
void something() {}
};
class SecondChild : public Base
{
public:
void something() {}
};
std::vector<Base*> vbase;
Child * tmp = new Child();
vbase.push_back((Base*) tmp);
SecondChild * tmp2 = new SecondChild();
vbase.push_back((Base*) tmp);
for (std::vector<Base*>::iterator it = vbase.begin(); it != vbase.end(); it++)
{
//here's problem, I want to execute proper method "something", but only I can do is execute Base::something;
(*it)->something();
}
I don't know how to cast type, when I got many children of base class.