为什么this
不允许在静态成员函数的未评估上下文中使用?
struct A
{
void f() {}
static void callback(void * self) // passed to C function
{
static_cast< decltype(this) >(self)->f();
}
};
此代码给出错误:
错误:“this”对于静态成员函数不可用
static_cast< decltype(this) >(self)->f(); ^~~~
decltype(this)
需要简洁(有时它更短,然后VeryVeryLongClassName *
),另一个优点是意图更清楚。
this
关于在静态成员函数中未评估的上下文中使用的标准是什么?