I have a "chain" class, meaning a class that manages a sequence of objects with a common base class.
This chain class should execute the member function processSample(a, b)
for any child class (of baseClass
) I add.
I want to be able to code more child classes (with a processSample(a, b)
function) later on, and add them to the chain without having to edit the chain class.
I could use a template in the add
function but this doesn't solve the problem that there is no data structure for different datatypes (of different sizes) right?
Functions of the children called in the Chain
class should all be overridden virtuals from the base class.
class baseClass
{
public:
virtual float processSample(int a, float b)
{
}
};
class Chain
{
const int maxChilds = 20;
?sometype? allChilds[maxChilds];
public:
float processSample(int c, float d)
{
for (int i = 0; i < maxChilds; i++)
{
input = allChilds[i].processSample(a, b);
}
return input;
}
void addChild(?sometype? newChild)
{
allChilds.push_back(newChild)
}
}