Re: Is MSDN wrong? or I made a mistake? about static member function



On Mon, 10 Jul 2006 21:59:36 GMT, "David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx>
wrote:


"Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote in message
news:nib5b2pcb5l48j1tlu78fcaia5bnjfcv3r@xxxxxxxxxx
Static member functions can be called using that syntax, but the object
reference or pointer isn't evaluated. So for a static member function, the
following are equivalent:

p->f();
T::f();

The second one is much better style.

One of my pet peeves against C# is that it uses '.' for both "->" and "::",
making it not obvious what is a static member, or for that matter, a heap or
stack allocated instance. Unless I'm wrong, I'm no C# expert.... Things
like this make me wonder if it really is an improvement over C++.

I think C# is better, because it doesn't allow:

obj.StaticFunction();

You must instead say:

ClassName.StaticFunction();

Note also that in C++, the meaning of T::f() depends very much on the
context of the call. If it occurs inside a non-static member function, it
could be a static or non-static member function call, and you have to look
at the class and possibly its bases to determine what it means. Wherever it
occurs, it could be a call to a function in a namespace T.

--
Doug Harrison
Visual C++ MVP
.


Loading