Article View: comp.std.c++
Article #2304Re: Can I declare private constants?
From: Steve Clamage
Date: Thu, 26 Oct 1995 02:25
Date: Thu, 26 Oct 1995 02:25
29 lines
1706 bytes
1706 bytes
In article 2cn@meg.tesser.com, ralphs@tesser.com (Ralph Shnelvar) writes:
>
>I've been following this thread for a while (but not, obviously, from
>the beginning), and I don't understand why you guys aren't using the
>"enum hack" to simulate a class static constant?
You can use the enum hack, but it isn't necessary. You can now (if
your local compiler supports the change) declare a static member of
any integral type as a manifest constant:
class Foo {
public:
static const unsigned short max = 1024;
...
private:
char buf[max];
};
One advantage, not evident in this simple example, is that you can choose a
suitable type for 'max'.
The discussions have revolved around why it is, and whether it should continue
to be, necessary to provide a definition
unsigned short Foo::max;
at namespace scope in one and only one place in the program.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ 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:
<46lll7$826@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backReferences:
<46ldi4$2cn@meg.tesser.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back Date: 26 Oct 95 02:25:55 GMT Approved: fjh@cs.mu.oz.au From: clamage@eng.sun.com (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Can I declare private constants? X-Original-Date: 25 Oct 1995 15:38:15 GMT Organization: Sun Microsystems Inc. Message-ID: <46lll7$826@engnews2.Eng.Sun.COM> References: <46ldi4$2cn@meg.tesser.com> Reply-To: clamage@eng.sun.com X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMI7xw+EDnX0m9pzZAQGY5AF9Ez236T2SSPGdD4pZ0kcm6sBq7LshuoVZ syS4OzpEePSRWdYKttpPzzTwHw55PEv+ =Mtzn