7.0 Classes
Both "get" and "set" access methods should be "inline" where the publication of a data "feature" fits the class abstraction. In otherwords, it is not reqiured that all data members have access methods.
7.8.2 Use const for "get" access methods. (R)
The "get" access methods should be const methods. Failure to do so will make it impossible to use a "get" method on a const object.
7.8.3 Avoid non- const "get" method return types (GL)
Never return a non-const reference to a data member in a "get" access method, unless it is a simple built-in type (ie, int or char). This used to cause the generation of a temporary since the "type" of "this" is "const", and is now an error (some compilers do not yet catch this).
Example:
class X
{
private:
TString fName;
public:
TString& name() const { return fName; } // bad
};
void foo()
{
TString& s = x.name (); // ref to temporary
...
};
Generated with CERN WebMaker