TITLE: Dangerous references! PROBLEM: I would like to see support for a language feature which would allow data members to be public and read only. Example class COORD { public: int x,y; // read only }; RESPONSE: Niklas Hallqvist (niklas@appli.se) class COORD { int _x; int _y; public: const int& x; const int& y; COORD() : x(_x), y(_y) {} }; int main(int, char**) { COORD p; int X = p.x; int Y = p.y; // p.x = X; // ERROR! // p.y = Y; // ERROR! } As you can see, no new language constructs are needed. RESPONSE: Stephen Adams (sra@ecs.soton.ac.uk) At first I thought that it was a nice idea. Now I am not so sure. There are problems: 1. The copy constructor must also initialize z in this way (easily forgotten). If it does not, z in the copy will refer to zP in the original object. It might take a lifetime to figure out a bug like that. 2. An assignment operator is equally tricky: it can't be the bitwise for the same reasons as (1). Assignment has to copy everything else by hand. (The destination object has already had the references set up by its constructor.) 3. For various reasons like the above, in the general case the reference has to be stored as a pointer. In this example this doubles the size of the object (so might halve the speed of the program). In view of these disappointments I think that I will stick with the `.z()' syntax. I am used to parentheses - I used to be a lisp programmer :-)