16 Jul
2008
16 Jul
'08
8:08 p.m.
AMDG Meryl Silverburgh wrote:
Thank you. You said 'btw, do you really wish to return the reference?' , Can you please tell me what do you mean, like what kind of problems it will cause?
The potential problem is if the reference outlives all the shared_ptrs. Whether this is an actual problem or not depends on how getB is used. If the result is a short-lived reference, then it's safe. If the result is saved somewhere, it's safer to return a shared_ptr to make sure that the object doesn't get destroyed from underneath you. In Christ, Steven Watanabe