Article View: comp.std.c++
Article #28Private static member functions
From: Tucker Taft
Date: Mon, 02 Nov 1992 15:29
Date: Mon, 02 Nov 1992 15:29
53 lines
2989 bytes
2989 bytes
It would be very useful to allow private static member
functions to be declared outside the class declaration.
For example:
private static void C::helper(C* p)
{
/* This function does something useful */
/* that depends on access to private members of C */
}
Such a declaration would be visible within its file only, and
only to other member functions of the same class (or their
friends in the same file).
This could dramatically reduce recompilation problems
in environments where any change to a ".h" causes massive
recompilation. Such private static member functions
are useful to keep the size of the visible member functions
of a class reasonably small. However, if one must broadcast
everytime such a new private static member function is added,
the incentive will be to just make the visible member bigger,
copying code rather than sharing it between member functions
of the same class, etc.
This does not open any access "holes" because such a
"local" private static member can only be reached through
some "global" member function. It is just a way to
carve off some shared functionality into a separate function,
something that a class implementor/maintainer should be able
to do without disturbing any clients of the class.
There was a recent flurry about completely omitting the private
part from a class declaration. This doesn't work too well
for non-function members because it interferes with compile-time
size determination. This is a surmountable problem, but typically
requires some implicit level of indirection and an extra
mark/release stack (any language that allows local variables
of compile-time-unknown size already solves this problem,
e.g. Algol 60 did it 32 years ago, but it does introduce
overhead and complexity). It gets worse when you have
instances of such classes as members of other classes -- the
dynamicity of size spreads.
On the other hand, there is no implementation-related need
to require that the declaration of private static member
functions appear in a globally visible place. This has been
pointed out in the past, and one justification for the requirement
has been that the existence of such functions is somehow
part of the "abstraction." This seems like a pretty
weak argument (there may be other stronger arguments, but
I am not aware of them).
S. Tucker Taft stt@inmet.com
Intermetrics, Inc.
Cambridge, MA 02138
Technical Details
Message-ID:
<1992Nov2.152918.469@inmet.camb.inmet.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!sequent!ogicse!decwrl!sdd.hp.com!swrinde!elroy.jpl.nasa.gov!ames!think.com!rpi!bu.edu!inmet!spock!sttShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!sequent!ogicse!decwrl!sdd.hp.com!swrinde!elroy.jpl.nasa.gov!ames!think.com!rpi!bu.edu!inmet!spock!stt From: stt@spock.camb.inmet.com (Tucker Taft) Newsgroups: comp.std.c++ Subject: Private static member functions Message-ID: <1992Nov2.152918.469@inmet.camb.inmet.com> Date: 2 Nov 92 15:29:18 GMT Article-I.D.: inmet.1992Nov2.152918.469 Sender: news@inmet.camb.inmet.com Distribution: comp.std.c++ Organization: Intermetrics Inc, Cambridge MA Lines: 53 Nntp-Posting-Host: spock