quote:inline const int& getX() const { return x; }inline int getX() const { return x; }// are valid
and remember, for primitive types it is more efficient to return the value than the reference ... and nobody's syntax using it needs to change, so choose the second option above for this case.
Yes, but as was discussed in another thread recently, the const-ness can be cast away by a well-meaning programmer that's trying to be clever:
const_cast<int &>(f.geti()) = 666;
I like your final suggestion - return a copy of the int, not a reference (even a const one) to it.
As an aside, if you notice that certain classes are always twiddling with the private members of another class, it's a good sign that a refactoring is in order. Perhaps the "twiddler" and "twiddlee" need to be merged.
EDIT: Stupid source tags!
--
Dave Mikesell Software & Consulting [edited by - dmikesell on November 12, 2003 10:31:50 AM]