const_castで消しされないconstが存在する。関数へのポインターにおける関数の型や、メンバー関数へのポインターにおけるメンバー関数の型だ。
void f(int const *) {}
struct C
{
void f() const {}
} ;
int main()
{
// これが普通
void (*ok_1)(int const *) = &f ;
// ill-formed.
// 関数の仮引数のconstを消そうとしている
void (*error_1)(int *) = const_cast<void (*)(int *)>(&f) ;
// これが普通
void (C::*ok_2)() const = &C::f ;
// ill-formd.
// メンバー関数のconstを消そうとしている
void (C::*ok_2)() = const_cast<void (C::*ok_2)()>(&C::f) ;
}
こんなconstが消せてたまるか。
No comments:
Post a Comment