Article View: comp.std.c++
Article #2284Re: Can I declare private constants?
From: Mike Rubenstein
Date: Mon, 23 Oct 1995 17:40
Date: Mon, 23 Oct 1995 17:40
48 lines
2014 bytes
2014 bytes
martelli@cadlab.cadlab.it (Alex Martelli) wrote:
>st@mlc-ratingen.de writes:
> ...
>>> Note that you still need a definition of X::fifty somewhere:
>>>
>>> int X::fifty;
>
>>This one has always puzzled me. What is the rationale behind *still*
>>requiring that X::fifty be defined somewhere if it is initialized in
>>the class declaration?
>
>Suppose the program, in various different source files, takes the address
>&X::fifty, and saves it in int* variables; then, at some later points,
>those variables are compared for equality of their contents. We want
>to ensure that such equality holds. That the _contents_ of X::fifty
>are defined in the header seen by each such source file has obviously
>no relevance to this -- the _location_ of it must also be defined,
>and, clearly, it will have to be in exactly one place to guarantee
>the equality holds...
Why must it be defined in only one place. Consider
class A
{
public:
static const int c = 1;
void f()
{
static const int i = 1;
...
}
}
in a header.
The compiler must create only one copy of i no matter how many
translation units include the header. Why can't the mechanism that
does this also be used for c?
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:
<46f8lv$oct@ixnews6.ix.netcom.com>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<9509118134.AA813443405@intugate.intuit.com> <9528514.26968@mulga.cs.mu.OZ.AU> <s6burc43zt.fsf@kirk.mlc-ratingen.de> <martelli.814356512@cadlab>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: miker3@ix.netcom.com (Mike Rubenstein) Newsgroups: comp.std.c++ Subject: Re: Can I declare private constants? Date: 23 Oct 1995 17:40:27 GMT Organization: Netcom Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <46f8lv$oct@ixnews6.ix.netcom.com> References: <9509118134.AA813443405@intugate.intuit.com> <9528514.26968@mulga.cs.mu.OZ.AU> <s6burc43zt.fsf@kirk.mlc-ratingen.de> <martelli.814356512@cadlab> NNTP-Posting-Host: physics2.berkeley.edu