Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr vs pass object by reference
From: Patrick Loney (patrick.loney_at_[hidden])
Date: 2010-07-29 05:10:59

> Can I still pass that pointer by value into a function like I did with shared_ptr in the
> above example?

No, you can't take a copy of a scoped ptr, when one goes out of scope it automatically causes the pointed to object to destruct, if there are two scoped ptrs pointing to the same object what would happen when the second is then used to access the already destructed object? You can pass scoped ptrs by reference, use shared pointers when you want multiple objects to have ownership of the pointed to object (i.e. no object can destroy the contents of the shared pointer while another object still needs it).

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at