Consider the following code:
struct Foo
{
mutable int m;
template<int Foo::* member>
void change_member() const {
this->*member = 12; // Error: you cannot assign to a variable that is const
}
void g() const {
change_member<&Foo::m>();
}
};
Compiler generates an error message. The thing is that the member m
is mutable therefore it is allowed to change m
. But the function signature hides mutable declaration.
How to decalre pointer-to-mutable-member to compile this code? If it is impossible please link to Standard C++.