> On Dec 2, 2015, at 10:41 PM, Clark Cox <clarkc...@gmail.com> wrote: > >> Widget *w = factory.getCurrentWidget(); >> Paint *p = w->getPaint(); >> If the currentWidget is NULL, the second line does this. > > That counts as a pointer dereference (the special case of &*foo is just that, > a special case).
It syntactically looks like one, but it isn’t one. “Dereference” means referencing, i.e. accessing, the memory location pointed to. A nonvirtual method call doesn’t do that. The reason it’s undefined in the standard to dereference NULL is because on almost all operating systems that’s unmapped memory and will cause a crash. It isn’t just because of squeamishness about what the LHS of a -> operator should be. > On Dec 2, 2015, at 10:22 PM, Marco S Hyman <m...@snafu.org> wrote: > > Isn’t it a compiler implementation detail that w->getPaint under the covers > turns into getPaint(w)? In many languages I’d agree with you. But C++ has a very explicit design principle of not adding extra overhead unless you ask for it. If you want the more powerful (but slower) behavior of virtual methods (inheritance, etc.) you have to explicitly say “virtual”; otherwise a method call is implemented just like a regular C function call. —Jens
_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (Xcode-users@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com This email sent to arch...@mail-archive.com