Article View: comp.std.c++
Article #2385Continue: static func() const; legal?
From: Bret Pehrson
Date: Wed, 01 Nov 1995 20:34
Date: Wed, 01 Nov 1995 20:34
45 lines
1738 bytes
1738 bytes
A while back I asked whether the following was legal:
class base
{
static funkie(void) const;
};
I received two responses, both of which said (paraphrased):
It is not legal, and does not make sense because 'const' implies that
the this pointer is constant, and since 'static' members do not have
a this pointer, it is meaningless.
After some thought, I would like to repose the question:
Suppose:
class base
{
static void lumpy(void) const;
static int cLumps;
};
int base::cLumps = 0;
void base::lumpy(void)
{
++cLumps;
}
Now, since cLumps is a member of base, albeit static, making a static
member function 'const' would mean that it does not change available
class members (in this case, static member variables).
So, with this above sample, I can definitely see a legitimate need
for static const member functions.
Legal or not?
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<478k57$5gl@stellar.comnet.com>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: Bret Pehrson <BretP@strata3d.com> Newsgroups: comp.std.c++ Subject: Continue: static func() const; legal? Date: 1 Nov 1995 20:34:14 GMT Organization: STRATA, Inc. Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <478k57$5gl@stellar.comnet.com> NNTP-Posting-Host: taumet.eng.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; conversions="7bit" Content-Transfer-Encoding: 7bit X-Nntp-Posting-Host: bretp.strata3d.com X-Mailer: Mozilla 1.22 (Windows; I; 32bit) X-Lines: 41 Content-Length: 859 Originator: clamage@taumet