
On 4 May 2011 13:42, Marsh Ray <marsh@extendedsubset.com> wrote:
On 05/04/2011 01:12 PM, Olaf van der Spek wrote:
On Wed, May 4, 2011 at 7:51 PM, Denis Shevchenko <for.dshevchenko@gmail.com> wrote:
No, it's not dogma. Raw pointers are not the universal evil, but I never use raw pointers because I *can* write my code without raw pointers. :-)
That still doesn't tell me why that's better in this case.
Because it uses the C++ type system to restrict the number of possible interpretations about the valid operations on the returned value, thus communicating information that would otherwise go unspecified.
If, for instance, you pass a shared_ptr, you are saying that the callee is allowed to be involved with ownership. This is functionality I typically don't want to grant willy-nilly to every function I call. If you want to use the C++ type system to enforce this kind of thing, create new types to wrap the raw pointers; don't reuse things like shared_ptr for this. (And if you are creating new types, then good for you, and I remove my objection. But it isn't typical, at least in my experience.)
Sometimes this lets the compiler help spot problems with the program's correctness.
Could you elaborate? Again, we are talking about pointers not involved with ownership. -- Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404