class BaseObject
{
virtualvoid Logic();
};
class Dog public: BaseObject
{
virtualvoid Logic(){};
};
class Cat public: BaseObject
{
virtualvoid Logic(){};
};
class Bird public: BaseObject
{
virtualvoid Logic(){};
};
std::list<BaseObject*> Objects;
Objects.push_back(new Dog());
Objects.push_back(new Cat());
Objects.push_back(new Bird());
for(std::list<BaseObject*>::iterator it = Objects.begin(); it != Objects.end(); it++)
(*it)->Logic();
That code, should do the logic for Dog and then for Cat and then for Bird, but what if I want to do the logic first for Bird and then Cat?. Would be Dog, Bird and Cat...
Can I do that? Do I need to change the positions inside the list, or should I use the iterator someway to first show Dog, Bird and then Cat, without modifying the list?
It might be better in this case to have the list in whatever order you need or just use different lists for different types. Though there is another thing you could do.
1 2 3 4 5 6 7 8
class Base{
virtualvoid logic();
virtualint type();
};
class Banana : Base{
int type() { return 5; }
};
The problem is that I'm making some kind of GUI, so I'm not only doing the logic of some objects but I'm also drawing them on the screen... So if I click over an object it should show up over the rest, for that reason I need to change the object positions inside the list.