For my project I have this class structure :
class Base
{
enum class type
{
Derived1,
Derived2
}
int getType() {return type;};
type type;
//general methods & attributes
}
class Derived1 : public Base
{
//specific methods & attributes
void uniqueSpecificMethodOfDerived1();
}
class Derived2 : public Base
{
//specific methods & attributes
void uniqueSpecificMethodOfDerived2();
}
class Core
{
vector<unique_ptr<Base>> tab;
void iterate();
}
void Core::iterate()
{
tab.emplace_back(new Derived1());
tab.emplace_back(new Derived2());
vector<unique_ptr<Base>>::iterator it;
for (it = tab.begin(); it != tab.end(); ++it)
{
if ((*it)->getType())
(*it)->uniqueSpecificMethodOfDerived1(); //unknow function Can't resolve 'uniqueSpecificMethodOfDerived1()'
if ((*it)->getType())
(*it)->uniqueSpecificMethodOfDerived2(); //unknow function Can't resolve 'uniqueSpecificMethodOfDerived1()'
}
}
My problem is I can't reach the specific methods of derived class in this vector. And I do not want to use polymorphism because this functions are totally different and not needed by other derived classes.
How I can do that ?