Question regarding const

Hi all

What's does the reserved word const mean when used in the following context:

class myclass{

void myclass::mymethod() const {};

}

I know the meaning of const when used in the return value or the parameter list, but in the previous situation.

Thanks in advance
Pedro
[338 byte] By [PedroES] at [2007-11-18 18:20:22]
# 1 Re: Question regarding const
It means that the function cannot change any of the class data members. Effectively, it tells the caller of this function that the function itself will not change the object in any way.

Effectively, it makes the "this" pointer constant.

Viggy
MrViggy at 2007-11-9 0:31:30 >
# 2 Re: Question regarding const
Effectively, it tells the caller of this function that the function itself will not change the object in any way.Which then means you can call the function for a const object.
class myclass{
public:
void mymethod() const {};
void myothermethod() {};
};

myClass a;
const myClass b;

a.mymethod(); //OK
b.mymethod(); //OK
a.myothermethod(); //OK
b.myothermethod(); // Error
One more thing: Member functions declared as const may change member variables declared as mutable.
treuss at 2007-11-9 0:32:27 >
# 3 Re: Question regarding const
Ahhh, yes, I forgot about the 'mutable' keyword. Thanks treuss!!!

Viggy
MrViggy at 2007-11-9 0:33:25 >