yep nothing strange about that.
The const means you can't modify any of the classes member variables so modifying the parameter passed in isn't surprisingly. While:
void foo(const int x) constis what prevents the modification of a parameter
Since the dereference is just memory somewhere you aren't modifying the ptr ptr , but rather what the pointer is pointing to which sounds normal. So operations like
or are prevented by the const as you are actually modifying the member variable.
What is a bit interesting is that you can indirectly modify a member variable in a const function.
Code:
class A{
int* ptr;
int g;
A(){g = 5; ptr = &g}
void foo(int x) const{
++*ptr; <--- Modifies the member variable g despite being a const.
}
};