I am programming in c++11 and boost and i am trying to implement some kind of framework where someone just needs to inherit from class Base and implement method(), which may depend on other inheritances. These inheritances should then be automatically created in the main function, without any modification by the programmer.
class Base
{
public:
virtual void method() = 0;
}
class A : public Base
{
public:
static int state = 0;
void method() //
{
//do something with B
A::state = B::state * 3;
}
}
class B : public Base
{
public:
static int state = 0;
void method() //
{
//do something with A
B::state = A::state * 2;
}
}
int main()
{
//Access to an Array containing ONE pointer to each Inheritance
vector<Base*> inheritancesOfBase;
inheritancesOfBase.push_back(new A); // <- should be done automatically
inheritancesOfBase.push_back(new B); // <- should be done automatically
//PSEUDOCODE
for_each(base* pInh in inheritancesOfBase)
{
pInh->method();
clones.push_back(pInh->clone());
}
return 0;
}
I think this should be doable with some fancy metaprogramming, but how?
EDIT: clarification