29 Jul
2010
29 Jul
'10
9:10 a.m.
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).