Article View: comp.std.c++
Article #45Re: Private static member functions
From: Tucker Taft
Date: Wed, 04 Nov 1992 15:52
Date: Wed, 04 Nov 1992 15:52
55 lines
2526 bytes
2526 bytes
In article <1992Nov3.002354.672@frumious.uucp>
uunet.ca!frumious!pat writes:
>stt@spock.camb.inmet.com (Tucker Taft) writes:
>|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.
>
>Since you're only asking for this for static member functions,
>you can get pretty much the same effect in the existing language,
>by using a friend class.
>
> class C {
> // ...
> friend class FriendOfC;
> };
>
>Put the static member functions in FriendOfC instead of C; then
>you can add or remove functions without forcing the users of C
>to recompile.
Neat trick. But why force every programmer who might someday
want to add a local static private member function to the
implementation of a class to use this trick? Why
not just make the capability a part of C++, consistent with
good software engineering principles and information hiding?
Other languages that have the concept of a module
recognize that you shouldn't have to declare in the interface
to the module all functions local to the implementation of the
module, just because they see the private declarations of the
module. In C++, the class is the module, and the class declaration
is its interface. Forcing all private static member functions to
appear there is a real hindrance to reasonable implementation
modularity.
>Patrick Smith
>uunet.ca!frumious!pat
>pat%frumious.uucp@uunet.ca
S. Tucker Taft stt@inmet.com
Intermetrics, Inc.
Cambridge, MA 02138
Technical Details
Message-ID:
<1992Nov4.155210.11633@inmet.camb.inmet.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!news.gtech.com!noc.near.net!inmet!spock!sttReferences:
<1992Nov2.152918.469@inmet.camb.inmet.com> <1992Nov3.002354.672@frumious.uucp>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!news.gtech.com!noc.near.net!inmet!spock!stt From: stt@spock.camb.inmet.com (Tucker Taft) Subject: Re: Private static member functions Message-ID: <1992Nov4.155210.11633@inmet.camb.inmet.com> Sender: news@inmet.camb.inmet.com Nntp-Posting-Host: spock Organization: Intermetrics Inc, Cambridge MA References: <1992Nov2.152918.469@inmet.camb.inmet.com> <1992Nov3.002354.672@frumious.uucp> Date: Wed, 4 Nov 1992 15:52:10 GMT Lines: 55