How Remove An Element Of A List

How can I remove an element in a list when I have only an iterator that points to the object I want to remove. Is there a build in command? remove() takes an object reference as its argument. Is it possible to convert the iterator into a pointer type so it can be deferenced and passed to remove?

This is the code I am working on:

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
//player.cpp
void Player::CheckCollectableCollisions(std::list<Collectable>& c)
{
    std::list<Collectable>::iterator i = c.begin();

    while(i != c.end())
    {
        if (Collider::CheckCollision(pNodes_.front().getLocation(), i->getLocation()))
        {
            AddNode(i->GetMealSize());
            creator_.getCollectableManager().Remove(i);
        }
        i++;
    }

}
//CollectableManager.cpp - this is the function I am trying to work out how to implement
//mainly what parameters should it have?
void CollectableManager::Remove(std::list<Collectable>::iterator col)
{
    std::list<Collectable>::iterator i = collectables_.begin();
    
    while (i != collectables_.end())
    {
        if (i == )
    }
}

Thanks.
1) there is erase() which takes an iterator
2) iterators can be dereferenced by definition ( http://en.cppreference.com/w/cpp/concept/Iterator , http://en.cppreference.com/w/cpp/concept/ForwardIterator ). Think of them as of pointers on steroids.
Thanks, pointers on steroids :)
Topic archived. No new replies allowed.