Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!snorkelwacker.mit.edu!ira.uka.de!smurf!artcom0!hb.maus.de!hh.maus.de!Michael_Hoennig From: Michael_Hoennig@hh.maus.de (Michael Hoennig) Newsgroups: comp.lang.c Subject: MEMBER ACCESS ReadOnly Message-ID: <4197@hh.maus.de> Date: 4 Jun 91 19:39:00 GMT Article-I.D.: hh.4197 Distribution: world,comp Organization: Maus Mailbox Netz - UUCP-Gateway Bremen Lines: 43 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@starlab.UUCP -- ++49 40 23 08 56 (StarDivision Hamburg)