marknewlyn
asked on
Proper use of const regarding member functions
When defining a member function one can use the const keyword in a nubmer of places. I would like to check on the subtleties of location.
If my method merely returns an integer (say a counter) then I could define it thus:
int GetCounter() {return fCounter;}
If I want to ensure that the function does no change the member variables in any way I can add const
int GetCounter() const {return fCounter;}
What I would like to find out about is what it means exactly to use the const keyword in the following three cases:
int GetCounter() const;
const int GetCounter() {return fCounter;}
const int GetCounter() const {return fCounter;}
Thanks
If my method merely returns an integer (say a counter) then I could define it thus:
int GetCounter() {return fCounter;}
If I want to ensure that the function does no change the member variables in any way I can add const
int GetCounter() const {return fCounter;}
What I would like to find out about is what it means exactly to use the const keyword in the following three cases:
int GetCounter() const;
const int GetCounter() {return fCounter;}
const int GetCounter() const {return fCounter;}
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.