Article View: comp.std.c++
Article #3910Re: Const class member
From: David Vandevoorde
Date: Wed, 03 Apr 1996 17:22
Date: Wed, 03 Apr 1996 17:22
38 lines
2003 bytes
2003 bytes
>>>>> "TH" == Torsten Hoff <thoff@symantec.com> writes:
[...]
TH> If you *really* want compile-time initialized constants, and can live
TH> with something that has essentially the same properties as an integer,
TH> use class-scope enums. If you need several compile-time constants with
TH> the same value, you can use multiple untagged enums:
TH> class AnyClass
TH> {
TH> enum {FOO = 1, BAR = 1}; // multiple enums with same value;
// doesn't work!
TH> enum {FOO = 1}; // OK
TH> enum {BAR = 1}; // OK
TH> }
[...]
Alternatively:
struct AnyStruct {
static bool const Yes = true;
static char const A = 'B';
};
(Somewhere:
bool const AnyStruct::Yes;
char const AnyStruct::A;
)
which works for integral types (if you compiler is reasonably up-to-date).
Daveed
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<xsolokd1gum.fsf@avs.cs.rpi.edu>Path:
arc1-ca.pugleaf.net!fido.asd.sgi.com!austernReferences:
<4jgpqa$t09@nntp.interaccess.com> <4jq60l$6pp@symiserver2.symantec.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern From: vandevod@cs.rpi.edu (David Vandevoorde) Newsgroups: comp.std.c++ Subject: Re: Const class member Date: 03 Apr 1996 09:22:55 PST Organization: RPI Computer Science Approved: austern@isolde.mti.sgi.com Message-ID: <xsolokd1gum.fsf@avs.cs.rpi.edu> References: <4jgpqa$t09@nntp.interaccess.com> <4jq60l$6pp@symiserver2.symantec.com> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 03 Apr 1996 10:12:49 -0500 In-Reply-To: thoff@symantec.com's message of 02 Apr 96 13:30:31 GMT X-Newsreader: Gnus v5.1 X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMWKz8Ey4NqrwXLNJAQGmvgH/awUOAD0g/s1q5E/GJ6u7WqOaW/3msCkf /EX+WEKScnKz2g5XUa9MgUt30upNa68A9KGfqPEFIid4srlPKbMp4Q== =IwNo Originator: austern@isolde.mti.sgi.com