class sample {
int n;
public:
void set( int i )
{ n = i; }// Changing n is intended
int get() const
{ return n }// Cannot (does not) change n
}
You can indicate that the return value is in some sense constant:
const int n = 1; //hereafter n is constant
int const v() { return n; }
const int w() { return n; }
const int* x() { return &n; }
int* const y() { return &n; }
// error return of non-const*
// pointer from const*
const int* const z() { return &n; }
|