Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!comp.vuw.ac.nz!am.dsir.govt.nz!marcamd!mercury!fivegl!struan From: struan@fivegl.co.nz (Struan Judd) Newsgroups: comp.lang.c++ Subject: Re: Proposal: 'virtual' class members for C++ Summary: Another-way Keywords: const reference Message-ID: <1991May27.231239.5546@fivegl.co.nz> Date: 27 May 91 23:12:39 GMT References: <1745@culhua.prg.ox.ac.uk> <1991May24.170014.17301@kestrel.edu> Sender: struan@fivegl (Struan Judd) Reply-To: struan@fivegl (Struan Judd) Followup-To: comp.lang.c++ Organization: 5GL International Ltd, Auckland, New Zealand Lines: 51 In article <1991May24.170014.17301@kestrel.edu> gyro@kestrel.edu (Scott Layson Burson) writes: >In article <1745@culhua.prg.ox.ac.uk> bill@robots.oxford.ac.uk (Bill Triggs) writes: >>I would like to propose a simple extension of C++ syntax >>which would allow 'soft' or 'virtual' class members to be >>simulated by member functions. >> >>[...] > >I like the basic idea of having things that look like member variables >that are actually member function invocations. However, I don't like > >[...] > >-- Scott >Gyro@Reasoning.COM Throwing my $0.02 into the ring on this general subject, I quite like using the following style. While it does not hide the fact that assignments to variables are being done through a function interface, it does allow non-friends of the class 'access' to some of the member variables of the class. Example: class Scr_Location { private: unsigned char SL_Left, SL_Top, SL_Right, SL_Bottom; public: Scr_Location(void); . . . const unsigned char &Left = SL_Left, &Right = SL_Right, &Top = SL_Top, &Bottom = SL_Bottom; . . . }; (Question: It would be very nice if C++ compilers could recognise this construct and not actually reserve storage in the class instances for the references. Do any do this?) This works for me as I tend to only have code executed when variable values are changed not when they are merely obtained. -- +------------------------------------------------+---------------------+ | Struan L. Judd | struan@fivegl.co.nz | | Of all the bit boxes in this electronic world, | PH: +64 9 302-1621 | | this message had to shift into this one. | FAX: +64 9 302-1617 |