Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • I would use std::auto_ptr<> to show that owner ship is being transferred (rather than RAW pointer). Presumably you are already storing in a smart pointer, if sole ownership is expected std::auto_ptr<> is perfect. Commented Oct 2, 2008 at 15:22
  • The OP said he couldn't use generics, which presumably rules out any smart pointer type. Commented Nov 25, 2008 at 19:10
  • Wont application core dump if the object pointed by the reference is deleted by mistake? If it had been a pointer, we could check for null.(provided the deleter sets it to null.) Commented Oct 10, 2011 at 8:45
  • @balki It might; it might not; it might make toasters rain from the sky: it's UB. But Sander said references are only used if there's a guarantee they don't become dangling, so that's a code quality issue. And more important, pointers are no better: deletion of the object by another entity doesn't set the observer's copy of the pointer to nullptr, so it can't be tested for validity anymore than a reference can (read: nullptrness is a property of an address, not the data at that address) ...unless each observer ptr is registered by ref w/ the owner for later updating or something convoluted Commented Jan 17, 2017 at 1:24