Tuesday, July 28, 2009

What does this mean?

I am trying to learn c++ and I ran into something like this


void methodName() const; in a header file declaring variables and methods. Now I know what void methodName does, but I don't know what the const keyword means at the end. The only other place I have seen const is when you are declaring a global variable.

What does this mean?
Member functions should be declared with the const keyword after them if they can operate on a const (this) object. If the function is not declared const, in can not be applied to a const object, and the compiler will give an error message. A const function can be applied to a non-const object





A function can only be declared const if it doesn't modify any of its fields.
Reply:i believe you are declaring a constant method / function





thats a pretty generic name, looks like you're using a Rapid Application Development platform.
Reply:I believe that means that this member function cannot alter the values of any member variables.


No comments:

Post a Comment