a question on function declaration
In the following class definition:
1 2 3 4 5
|
class X{
// ...
int m1( );
int m2( ) const;
}
|
what is the difference between function m1 and m2, or what is affected by adding a const to the declaration of m2?
A constant function does not modify the object for which it was called.
If you have a const object/reference to type X you can only call const methods.
The const qualifier can be used to overload a method
1 2 3 4 5
|
class X{
// ...
int m( ); // called by non-const objects
int m( ) const; // called by const objects
};
|
Topic archived. No new replies allowed.