| GBStudio (6) | |
|
Hi I'm new to C++ and I'm confused on something: int GetNum () const; Why const is after that? What is the difference between the code above and the one below: int const GetNum (); Thanks for your help Kindest Regards GBStudio | |
|
|
|
| ropez (310) | |||||||||
This function returns a const integer.
The const after the function can only be used on member functions. These functions have an implicit hidden parameter, which is a pointer to the object:
If the function is followed by const, the this pointer is const:
This means: * You can't change member variables in a function declared as const. * If an object is declared as const, you can only call functions that are declared const. * From a const member function, you can only call other member functions that are also const. | |||||||||
|
|
|||||||||
| GBStudio (6) | |
| Thanks a lot :) | |
|
|
|