Advertisement

\constant\ Member Functions

Started by April 17, 2001 08:39 AM
2 comments, last by Clash Rocker 23 years, 9 months ago
I once saw a C++ Class declaration like so: ...the following is only what I really can remember.
    
class CFoo
{
public:
    void whatever(bool something) const;
};
    
Now I don't think I know what that const is for on the end of that function prototype. Does it mean that this function (whatever()) does not change the class member variables? Edited by - Clash Rocker on April 17, 2001 9:41:17 AM
Yep. That means that the function doesn''t change the class''s member variables. Putting the const at the end of the function may enable the compiler to perform some sort of optimization.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Advertisement
I may be wrong, but as I recal there are situations in which an instance of a class can''t be modified. In this case, only functions declared as const can be called without the compiler yelling at you.

DZ
Oh smashing, thanks.


www.omf.com

This topic is closed to new replies.

Advertisement