Article View: comp.std.c++
Article #2321Re: Can I declare private constants?
From: Steve Clamage
Date: Fri, 27 Oct 1995 17:05
Date: Fri, 27 Oct 1995 17:05
47 lines
1935 bytes
1935 bytes
In article 74i@ixnews3.ix.netcom.com, miker3@ix.netcom.com (Mike Rubenstein) writes: >clamage@Eng.Sun.COM (Steve Clamage) wrote: >>In article 95Oct26140846@avs.cs.rpi.edu, vandevod@cs.rpi.edu (David Vandevoorde >>) writes: >>> >>>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 > >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. Gak! No, you are correct; I managed to confuse myself. The intialization of x is OK in C++. The expression two is a constant-expression, but the expression pi is not a constant-expression, which is the point I was trying to make. I should have quit while I was ahead :-( --- 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:
<46qudp$9qe@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<46pp4p$74i@ixnews3.ix.netcom.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Can I declare private constants? Date: 27 Oct 1995 17:05:27 GMT Organization: Sun Microsystems Inc. Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <46qudp$9qe@engnews2.Eng.Sun.COM> References: <46pp4p$74i@ixnews3.ix.netcom.com> Reply-To: clamage@Eng.Sun.COM NNTP-Posting-Host: physics2.berkeley.edu