- This topic has 2 replies, 2 voices, and was last updated 16 years, 5 months ago by .
Viewing 2 reply threads
Viewing 2 reply threads
- The forum ‘C Programming’ is closed to new topics and replies.
Home › Forums › C Programming › NEED HELP URGENTLY !!!!
hi to whoever reading this. I’m a complete noob to c++ so bare with me if it’s a simple question.
So, here goes my question:
What does the question mean by: implementing getter with const method?? Can anyone of you give me an example to this question??
Thanks
Do you mean a constant method of a class implementation? A constant member function of a class is a function that does not alter any class data members , like:
1 2 3 4 5 6 7 8 | class X<br /> {<br /> public:<br /> int age() const { return mAge; } //const get method<br /> void age(int age) { mAge = age; } //( accessor! )<br /> private:<br /> int mAge;<br /> }; |
check out this link: http://www.uwyn.com/resources/uwyn_cpp_coding_standard/x496.html
Thanks cman! Actually i was kinda confuse on where to put the “const”
For example:
1 2 | const int getName();<br /> int getName() const; |
what’s the difference between putting the “const” in front and at the back?