🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2678

Re: Can I declare private constants?

#2678
From: Steve Clamage
Date: Tue, 21 Nov 1995 16:38
48 lines
1698 bytes
In article ms2@rcogate.rco.qc.ca, ydanan@scir.ca writes:

>In <DGEFp4.IBC@bcstec.ca.boeing.com>, Kevin Ingalls <ingkl900@ccmail.ca.boeing.com> writes:

>>>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;
>>};

>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;

But why not use the method that preserves the original intent of having
fifty be a manifest constant?

class X {
	static const int fifty = 50;
};
and then in one place
	int X::fifty;

---
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: <48su7l$4hj@engnews1.eng.sun.com>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <48r6un$ms2@rcogate.rco.qc.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: clamage@Eng.sun.com (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Can I declare private constants?
Date: 21 Nov 1995 16:38:21 GMT
Organization: Sun Microsystems Inc.
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <48su7l$4hj@engnews1.eng.sun.com>
References: <48r6un$ms2@rcogate.rco.qc.ca>
Reply-To: clamage@Eng
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: taumet.eng.sun.com
Content-Length: 880
X-Lines: 44
Originator: clamage@taumet