Article View: comp.std.c++
Article #2648Re: Can I declare private constants?
From: ydanan
Date: Tue, 21 Nov 1995 03:10
Date: Tue, 21 Nov 1995 03:10
50 lines
1683 bytes
1683 bytes
In <DGEFp4.IBC@bcstec.ca.boeing.com>,
Kevin Ingalls <ingkl900@ccmail.ca.boeing.com> writes:
>Steven wrote:
>
>>class X
>>{
>>private:
>> const int fifty = 50;
>>};
>
>I assume that what you are really asking is "how can I accomplish this
>with legal syntax?" Given that, try this:
>
>class X
>{
> X() : fifty(50) {};
>private: // private, public, or protected actually has nothing
> // to do with it
> const int fifty;
>};
>
>-or-
>
>class X
>{
> X();
>private:
> const int fifty;
>};
>
>X::X() : fifty(50)
>{
>}
>
I am not saying that the proposed solution is wrong, but I want to propose
a simpler solution:
class X
{
static const int fifty;
..
};
int X::fifty = 50;
Of course there is only one copy of the constant in this example,
which is what the original example seemed to express.
[ 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:
<48r6un$ms2@rcogate.rco.qc.ca>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<9509118134.AA813443405@intugate.intuit.com> <DGEFp4.IBC@bcstec.ca.boeing.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 21 Nov 95 03:10:20 GMT Approved: fjh@cs.mu.oz.au From: ydanan@scir.ca Newsgroups: comp.std.c++ Subject: Re: Can I declare private constants? X-Original-Date: 21 Nov 1995 00:36:39 GMT Organization: Inter-Acces Communications Message-ID: <48r6un$ms2@rcogate.rco.qc.ca> References: <9509118134.AA813443405@intugate.intuit.com> <DGEFp4.IBC@bcstec.ca.boeing.com> Reply-To: ydanan@scir.ca X-Newsreader: IBM NewsReader/2 v1.2.5 X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMLFDTeEDnX0m9pzZAQG8vwF/WK+UiCsNmBbZZemGpq6VnuPGJW9AVnSZ uhm9JSC/y7juNVY1ZOkvku+JETPZVD1O =vhse