Article View: comp.std.c++
Article #2246Re: Proposal for a new access specifier
From: Ulf Schuenemann
Date: Wed, 18 Oct 1995 17:41
Date: Wed, 18 Oct 1995 17:41
81 lines
4396 bytes
4396 bytes
In article <MTM4.1251.012CDE71@rsvl.unisys.com>,
MTM4@rsvl.unisys.com (Mike McCormick) writes:
[..]
|> Since readOnly is volatile, it seems wrong for *ReadOnly to be static.
^^^^^^^^ - readOnly is nonstatic, nonconst,
nonvolatile and not mutable.
I forgot to make clear: I was looking for a way to avoid
that every instance gets an additional pointer (pReadOnly).
That's why I tried it with a static member.
To use a static member for access to nonstatic members,
Thing::ReadOnly is a memberpointer (memptr). Think of it as an
(static) offset into the object's dataspace (in the case of
memberDATApointer). A memptr of type (T C::*) can be applied to
any instance of class C using the .* (->*) syntax, yielding an
attribute of type T of this instance. Thus it is reasonable for
ReadOnly to be a static member of Thing (first try) or even
no member of Thing at all (second try).
--------------------------------------------------------------------
First try:
|> > t.*ReadOnly;
|> >This doesn't work, coz ReadOnly is unknown outside Thing!
|>
|> It's not so much that ReadOnly is unknown outside Thing (after all, it is
|> public) but rather that static members must be qualified by their class name.
Oops, you're correct.
[..]
|> > using Thing::ReadOnly;
|> >This doesn't work, coz a class is not a namespace.
|>
|> I thought this did work. See Stroustrup 2nd edition r.3.3.1.2.
I'd like it to work, but unfortunately 7.3.3 [namespace.udecl],5
(all citations from the Committee Draft, public review) prohibits
this and gives an example with static and nonstatic datamembers.
--------------------------------------------------------------------
Second try:
|> > const int Thing::*ReadOnly =Thing::&readOnly;
|> >Defining the memptr outside the class doesn't work
|> >coz Thing::readOnly not accessable (private).
|>
|> I thought this worked too. Stroustrup r.9.4 says static members have the
|> usual class accesses even though they are initialized in file scope.
Attention:
const int Thing::*ReadOnly = &Thing::readOnly;
^- here goes the &
This defines a variable of memberdatapointer type `const int Thing::*'
(see 8.3.3 [decl.mptr]). [ Definition of a datamember of type
`const int*' would look like (see 9.5.3 [class.static.data]):
const int* Thing::static_datat_member = ...; ]
[..]
|> > class Thing {
|> > friend const int Thing::*ReadOnly;
|> > };
|> > const int Thing::*ReadOnly = &Thing::readOnly;
^- here goes the &
So it would be nice to be able to allow such a nonmember variable
(here: global variable) access to private Thing::readOnly.
But this is not allowed, coz a variable can't be declared friend.
This is a hole in the language, IMHO.
Ulf Schuenemann
PS Sorry my answer's late, there were problems with MIME encoding.
--------------------------------------------------------------------
,_. Ulf Schuenemann
#, \ Fakultaet fuer Informatik, Technische Universitaet Muenchen, Germany.
| > email: schuenem@informatik.tu-muenchen.de
v=-< WWW: http://hphalle2.informatik.tu-muenchen.de/~schuenem/
[ 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:
<463dvv$smv@sunsystem5.informatik.tu-muenchen.de>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageReferences:
<199509221547.JAA10782@ncar.ucar.EDU> <MATT.95Sep24112332@Austern> <44spqj$j37@nn.fast.net> <MTM4.1214.010BD7A3@rsvl.unisys.com> <45e7po$3ov@sunsystem5.informatik.tu-muenchen.de> <MTM4.1251.012CDE71@rsvl.unisys.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: schuenem@informatik.tu-muenchen.de (Ulf Schuenemann) Newsgroups: comp.std.c++ Subject: Re: Proposal for a new access specifier Date: 18 Oct 1995 17:41:55 GMT Organization: Technische Universitaet Muenchen, Germany Sender: USENET Newssystem <news@informatik.tu-muenchen.de> Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <463dvv$smv@sunsystem5.informatik.tu-muenchen.de> References: <199509221547.JAA10782@ncar.ucar.EDU> <MATT.95Sep24112332@Austern> <44spqj$j37@nn.fast.net> <MTM4.1214.010BD7A3@rsvl.unisys.com> <45e7po$3ov@sunsystem5.informatik.tu-muenchen.de> <MTM4.1251.012CDE71@rsvl.unisys.com> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: hpbroy14.informatik.tu-muenchen.de Originator: schuenem@hpbroy14.informatik.tu-muenchen.de Content-Length: 3193 X-Lines: 77 Originator: clamage@taumet