Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-09-21 19:06:12


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;
>
> class Tank: public GameObject
> {
> weak_ptr<GameObject> target_;
>
> public:
>
> virtual void update()
> {
> if(shared_ptr<GameObject> p = make_shared(target_))
> {
> this->fireAt(p);
> }
> else
> {
> target_ = this->acquireNewTarget(objects);
> }
> }
> };
>
> The basic paradigm would be siblings that refer to each other.

Cool; mind if I use this example almost verbatim?

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com


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