왜 this
이 정적 멤버 함수에서 평가되지 않은 컨텍스트에 허용되지 않습니까? 또 다른 장점은 의도가 더 분명 사실이다 (가끔 그 다음, VeryVeryLongClassName *
훨씬 더 짧은)정적 멤버 함수의 평가되지 않은 컨텍스트에서
error: 'this' is unavailable for static member functions
static_cast< decltype(this) >(self)->f(); ^~~~
decltype(this)
간결이 필요합니다 :
struct A
{
void f() {}
static void callback(void * self) // passed to C function
{
static_cast< decltype(this) >(self)->f();
}
};
이 코드는 오류를 제공합니다.
정적 멤버 기능에서 평가되지 않은 상황에서 this
을 사용하는 것에 대해 어떤 표준이 말하는가?
의 가능한 복제 https://stackoverflow.com/questions/21143275/c-type-of-enclosing-class-in-static-member-function) –