Topic: this==0 ?


Author: rmartin@rcmcon.com (Robert Martin)
Date: Mon, 4 Apr 1994 14:01:12 GMT
Raw View
kanze@us-es.sel.de (James Kanze) writes:



>The standards committee recently decided that in the expression
>"f()->staticMember()", the function 'f' will be called.  (Usually, the
>name of the member function makes it somewhat less evident that it is
>static, and users tend to expect the function to be called when they
>write "f().")

Wait.  Does this mean that 'f' will be called in: "sizeof(f());" or in
"typeid(f());" ?  I wonder if it might not be better to disallow the
'.' or '->' mechanism for accessing static members; or at least
deprecate its use rather than enhancing its use.
--
Robert Martin       | Design Consulting   | Training courses offered:
Object Mentor Assoc.| rmartin@rcmcon.com  |   Object Oriented Analysis
2080 Cranbrook Rd.  | Tel: (708) 918-1004 |   Object Oriented Design
Green Oaks IL 60048 | Fax: (708) 918-1023 |   C++




Author: kanze@us-es.sel.de (James Kanze)
Date: 05 Apr 1994 13:38:55 GMT
Raw View
In article <1994Apr4.140112.625@rcmcon.com> rmartin@rcmcon.com (Robert
Martin) writes:

|> kanze@us-es.sel.de (James Kanze) writes:

|> >The standards committee recently decided that in the expression
|> >"f()->staticMember()", the function 'f' will be called.  (Usually, the
|> >name of the member function makes it somewhat less evident that it is
|> >static, and users tend to expect the function to be called when they
|> >write "f().")

|> Wait.  Does this mean that 'f' will be called in: "sizeof(f());" or in
|> "typeid(f());" ?

No, and I don't think so.

There is a major difference.  When you write "sizeof( f() )", 'f()' is
*never* called.  When you write "f()->someFunction()", 'f()' *must* be
called if 'someFunction()' is a non-static member.  Calling 'f()' for
some functions and not for others was deemed too confusing.

|>  I wonder if it might not be better to disallow the
|> '.' or '->' mechanism for accessing static members; or at least
|> deprecate its use rather than enhancing its use.

This might be fine for functions which are "contractually" static.
But what do you do if the fact that the function is static is
explicitly *not* part of the contractual interface, but rather an
implementation detail.  While not frequent, I have a few odd cases
like this; the comments make it clear that the `static' is just
because at present, the function doesn't need to access any non-static
members, this is *not* guaranteed in the future, and the user should
only use the function on an object.
--
James Kanze                       email: kanze@lts.sel.alcatel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                   -- Beratung in industrieller Datenverarbeitung