I would like to iterate over different objects that all inhereit from the same superclass. That means I have a superclass like this:
class fruit
{
public:
fruit()
{
}
};
And I have subclasses like this, which define the objects that are used in my code:
class apple: public fruit
{
public:
apple()
{
}
};
class banana: public fruit
{
public:
banana()
{
}
};
Now I want to iterate over all fruits (apples, bananas):
for ( first fuit; last fruit; next fruit )
{
// do something, no matter if apple or banana
}
But how should I do this since apples and bananas are different class types, but they share the same superclass. This is why I think, that there has to be an elegant way to do it.