Article View: comp.std.c++
Article #2188Re: Proposal for a new access specifier
From: Fergus Henderson
Date: Sat, 14 Oct 1995 08:53
Date: Sat, 14 Oct 1995 08:53
43 lines
2297 bytes
2297 bytes
h.b.furuseth@usit.uio.no (Hallvard B Furuseth) writes:
>MTM4@rsvl.unisys.com (Mike McCormick) writes:
>
>>>This is an example where it would be usefull to be able to initialize
>>>not only static but also nonstatic datamembers inside the class defn.
>>>
>>> class Thing {
>>> private:
>>> int readOnly;
>>> public:
>>> const int* const pReadOnly =&readOnly; // ILLEGAL
>>> };
>>
>> Just supposing this *were* legal syntax, how is it an improvement over the
>> constructor initializer syntax?
>
>If it were legal, pReadOnly need not take any space in the class becuase
>the compiler would always know where it pointed.
No, that's not true. The compiler would still have to reserve space
in the class for `pReadOnly', because you can take its address.
>Just like `const int &const pReadOnly = &readOnly;' might do if legal.
(You mean `... rReadOnly = readOnly;'.)
A compiler could do this optimization for references, like the above,
since you can't take the address of a reference.
But the optimization would not be valid for pointers.
--
Fergus Henderson | "Australia is the richest country in the world,
fjh@cs.mu.oz.au | according to a new system of measuring wealth
http://www.cs.mu.oz.au/~fjh | announced by the World Bank yesterday."
PGP: finger fjh@128.250.37.3 | - Melbourne newspaper "The Age", 18 Sept 1995.
---
[ 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:
<9528715.6285@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!MattReferences:
<199509221547.JAA10782@ncar.ucar.EDU> <MATT.95Sep24112332@Austern> <44spqj$j37@nn.fast.net> <MTM4.1214.010BD7A3@rsvl.unisys.com> <45e5v6$3ac@sunsystem5.informatik.tu-muenchen.de> <MTM4.1250.01029391@rsvl.unisys.com> <HBF.95Oct13120816@durin.uio.no>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Newsgroups: comp.std.c++ Subject: Re: Proposal for a new access specifier Date: 14 Oct 1995 08:53:39 GMT Organization: Computer Science, University of Melbourne, Australia Approved: Matt@Austern Message-ID: <9528715.6285@mulga.cs.mu.OZ.AU> References: <199509221547.JAA10782@ncar.ucar.EDU> <MATT.95Sep24112332@Austern> <44spqj$j37@nn.fast.net> <MTM4.1214.010BD7A3@rsvl.unisys.com> <45e5v6$3ac@sunsystem5.informatik.tu-muenchen.de> <MTM4.1250.01029391@rsvl.unisys.com> <HBF.95Oct13120816@durin.uio.no> NNTP-Posting-Host: austern.hip.berkeley.edu