K
krel
Two of the cases mentioned are:
- shared_ptr to a member that was allocated via new — this has tradeoffs
that are very similar to those of returning a member by pointer or by
reference; see those bullets for the tradeoffs. The advantage is that
callers can legitimately hold onto and use the returned pointer after
the this-object dies.
- local auto_ptr or shared_ptr to freestore-allocated copy of the datum.
This is useful for polymorphic objects, since it lets you have the
effect of return-by-value yet without the "slicing" problem. The
performance needs to be evaluated on a case-by-case basis.
Perhaps it's the wording, but I don't understand the difference between
these two, supposedly different, options.
- shared_ptr to a member that was allocated via new — this has tradeoffs
that are very similar to those of returning a member by pointer or by
reference; see those bullets for the tradeoffs. The advantage is that
callers can legitimately hold onto and use the returned pointer after
the this-object dies.
- local auto_ptr or shared_ptr to freestore-allocated copy of the datum.
This is useful for polymorphic objects, since it lets you have the
effect of return-by-value yet without the "slicing" problem. The
performance needs to be evaluated on a case-by-case basis.
Perhaps it's the wording, but I don't understand the difference between
these two, supposedly different, options.