Article View: comp.std.c++
Article #2157Re: Proposal for a new access specifier
From: mfinney
Date: Tue, 10 Oct 1995 15:02
Date: Tue, 10 Oct 1995 15:02
104 lines
3224 bytes
3224 bytes
In <DG6q6J.EEt@mv.mv.com>, ENGR@GSSI.MV.COM (Michael Furman) writes:
>It is so close to my ideal. But I have one addition. You described "abstract
>read source interface". I would like to have also "write interface": to let
>caller write just "square.Area = 10;" instead of "square.Change_Area(10)".
I have considered this issue for an extension of C++ (as a new language).
You might find my notes interesting...
"If we have the declaration...
int abc();
Then abc is a function taking no parameters and returning an
int. To call the function, it is necessary to write...
abc()
and to take the address of the function, it is necessary to
write either...
abc
or ...
&abc
It would be VERY convenient to be able to call the function
by writing
abc
but that would break too much C++ code.
The problem is that it is desirable to make all attribute
accesses use the same syntax. Therefore...
If we have the class definition...
class Abc
{
int x;
int y();
int z(int a);
};
Abc abc;
Then the members of the class may be accessed by...
abc.x();
abc.y();
abc.z(1);
The same form can be used when "abc." may be omitted as in a
member function. However, the more conventional form...
abc.x
can still be used, but will produce a warning message about
obsolete syntax. This warning message can be disabled by the
user. Further, referencing "abc.z" will return the address of
the member function z as a pointer to member, but will also
produce a warning message about obsolete syntax (which can also
be disabled).
Further, if it is desired to change the value of x, then
abc.x = 1;
can be used, but will produce a warning message about obsolete
syntax except in member functions. Again, this warning message
can be disabled. The preferred method is to overload the definition
of x, for example...
class Abc
{
int x;
int x(int a) {x = a;}
int y();
int z(int a);
};
Abc abc;
and then the syntax...
abc.x(1);
can be used. Since it is illegal to assign to a function (for
example...
abc.z = 1;
is illegal in C++), the assignment "x = a;" can be handled correctly."
Any comments?
Michael Lee Finney
[ 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:
<45d5r1$fk4@mujibur.inmind.com>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageReferences:
<199509221547.JAA10782@ncar.ucar.EDU> <MATT.95Sep24112332@Austern> <44spqj$j37@nn.fast.net> <DG6q6J.EEt@mv.mv.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: mfinney@inmind.com Newsgroups: comp.std.c++ Subject: Re: Proposal for a new access specifier Date: 10 Oct 1995 15:02:18 GMT Organization: In Mind, Inc. Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <45d5r1$fk4@mujibur.inmind.com> References: <199509221547.JAA10782@ncar.ucar.EDU> <MATT.95Sep24112332@Austern> <44spqj$j37@nn.fast.net> <DG6q6J.EEt@mv.mv.com> Reply-To: mfinney@inmind.com NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: finneyman.inmind.com X-Newsreader: IBM NewsReader/2 v1.2 Content-Length: 2242 X-Lines: 100 Originator: clamage@taumet