Changing std::list objects position

Hi, I'm new in this forum, and my English isn't the best one...

I'm trying to create a list using std::list this way (pseudo code):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

class BaseObject
{
    virtual void Logic();
};

class Dog public: BaseObject
{
    virtual void Logic(){};
};

class Cat public: BaseObject
{
    virtual void Logic(){};
};

class Bird public: BaseObject
{
    virtual void 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?

Thanks to all in advance.
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{
   virtual void logic();
   virtual int type();
};

class Banana : Base{
   int type() { return 5; }
};
1
2
3
for(...){
   if( (*it)->type() == 5 ) (*it)->logic();
}

You'd need three passes though.
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.
Well, then
1
2
3
Base* ptr = *iterator_to_the_selected_object;
list.erase(iterator_to_the_selected_object);
list.push_back(ptr);
Thank you for taking the time for reply, but this webpage says:


list::erase

Removes from the list container either a single element (position) or a range of elements ([first,last)).

This effectively reduces the list size by the number of elements removed, calling each element's destructor before.



I know that I'm passing pointers, but this wouldn't call the object destructor? Otherwise I think that would be a good solution.
No, this would only call pointer's destructor (of course, pointers can't have destructors).
I see, thank you very much for your help!. I was really stuck at this one.
Topic archived. No new replies allowed.