MEMBER ACCESS ReadOnly
Michael Hoennig
Michael_Hoennig at hh.maus.de
Wed Jun 5 05:39:00 AEST 1991
Hi Phil,
PC> A language feature I'd like to see...
PC>
PC> A class has certain data members, for efficiency reasons, I would like
PC>to grant the USER read-only access.
PC>
PC> class COORD
PC> {
PC> public:
PC> // Don't modify just read..
PC> int x,y;
PC> ...
PC> };
Try this:
class COORD
{
int x, y;
public:
COORD() { x=0; y=0; }
//...
const int &theX() const { return(x); }
const int &theY() const { return(y); }
};
int main()
{
COORD aCoord;
int x;
x = aCoord.theX();
aCoord.theY() = x;
return 0;
}
Bye
--
Michael Hoennig -- Dobbelersweg 45 -- D-2000 Hamburg 26 -- ++49 40 219 24 58
office: mi1 at starlab.UUCP -- ++49 40 23 08 56 (StarDivision Hamburg)
More information about the Comp.lang.c
mailing list