
On Wed, May 4, 2011 at 10:14 PM, Stewart, Robert <Robert.Stewart@sig.com> wrote:
void h() { foo * p = f(); delete p; // not unreasonable foo & r = g(); delete &r; // misuse }
g()'s interface returns a reference and not a pointer. That is a clear indication that g()'s caller does not own the memory. By contrast, f() returns a pointer. The caller is not unreasonable in thinking ownership might be transferred, particularly if local conventions indicate as much.
An interface that precludes the possibility for that sort of confusion is better.
You're ignoring the fact that such an interface makes normale usage more complex. Also, the difference between delete p and delete &r is very small, if the user does not understand how ownership works he might just write delete &r too. I don't get why you think it's reasonable to assume ownership is transfered by a find function. Olaf