
2 Jul
2011
2 Jul
'11
7:29 p.m.
Hmm -- so I guess, in the cases I'm talking about, I should store a shared_ptr, and just return a const refererence.
Note that it might be rather dangerous, if your caller would store such a const reference.
Then, if I need to have a copy of the member elsewhere to manipulate, I could return a weak_ptr.
Returning weak_ptr usually doesn't make sense (except for the case where you return it for tracking only). Note that shared_ptr is implicitly convertible to weak_ptr, so typically you return shared_ptr, and let the caller to decide what to do with it: if the caller indends to store it, but doesn't want strong referencing, it stores it as weak_ptr.