🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Can I declare private constants?

#2324
From: Mike Rubenstein
Date: Fri, 27 Oct 1995 14:55
48 lines
2404 bytes
clamage@Eng.Sun.COM (Steve Clamage) wrote:

>In article 95Oct26140846@avs.cs.rpi.edu, vandevod@cs.rpi.edu (David Vandevoorde
>) writes:
>>
>>>>>>> "SC" == Steve Clamage <clamage@eng.sun.com> writes:
>>[...]
>>SC> You can use the enum hack, but it isn't necessary. You can now (if
>>SC> your local compiler supports the change) declare a static member of
>>SC> any integral type as a manifest constant:
>>[...]
>>
>>Would you happen to know why it must be an ``integral type''?
>>I imagine uses for floating-point constants...
>
>I believe it is because integral constant-expressions are a special item
>in the language.  A floating-point constant-expression may consist only
>of floating-point literals. For example, at file scope:
>
>	const int two = 2; // 'two' is a constant-expression
>	int k = two; // OK
>
>	const double pi = 3.1415926535798;
>	double x = pi; // error, 'pi' is not a constant-expression
>
>So it seems to me that being able to write
>	struct T { static const double e = 2.7182818285; };
>doesn't give you any added capability or convenience compared to
>	struct T { static const double e; };
>because you must still provide a definition someplace.
>
>We might someday revisit the restrictions on floating-point constants,
>but it seems to me the rules are at least consistent.


Am I confused?  I thought that initializers of non-aggregates could be
any expressions, not just constant expressions and that

	double x - pi;

above was legal.

Michael M Rubenstein


[ 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: <46pp4p$74i@ixnews3.ix.netcom.com>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
References: <VANDEVOD.95Oct26140846@avs.cs.rpi.edu> <46ovik$s80@engnews2.Eng.Sun.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: miker3@ix.netcom.com (Mike Rubenstein)
Newsgroups: comp.std.c++
Subject: Re: Can I declare private constants?
Date: 27 Oct 1995 14:55:15 GMT
Organization: Netcom
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <46pp4p$74i@ixnews3.ix.netcom.com>
References: <VANDEVOD.95Oct26140846@avs.cs.rpi.edu> <46ovik$s80@engnews2.Eng.Sun.COM>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: ix-dc7-26.ix.netcom.com
X-Netcom-Date: Thu Oct 26 10:02:17 PM PDT 1995
X-Newsreader: Forte Agent .99b.112
Content-Length: 1487
X-Lines: 44
Originator: clamage@taumet