Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-22 09:09:15


From: "David Abrahams" <dave_at_[hidden]>
> From: "Peter Dimov" <pdimov_at_[hidden]>
>
> > > Is there an example which maps naturally onto non-intrusive use of
> > > weak_ptr?
> >
> > std::vector< shared_ptr<GameObject> > objects;
>
> Hmm...
>
> How do the GameObjects die when fired upon? Something has to remove them
> from the vector. Maybe you need std::set<> here instead?

fireAt(p) presumably invokes p->takeDamage(amount); now one of two things
happen, either takeDamage() removes 'this' from 'objects' (which would need
to be a std::list/set/map in this case to not invalidate iterators) or after
the for_each(&GameObject::update) loop there is another erase_if(objects,
&GameObject::isDead).

Or something like it.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk