glutIdleFunc
은 단순히 비 정적 멤버 함수 호출을 지원하지 않습니다. 유휴 루프에서 개체 메서드를 호출하려면 전역 변수에 개체에 대한 포인터를 배치하고 해당 전역 개체에 step
메서드를 호출하는 일반 함수 또는 정적 멤버가 있어야합니다.
이렇게 할 수있는 방법은 두 가지가 있습니다. 간단한 방법 : 약간 더 큰 캡슐화
// global scope
Core *foo = NULL;
void myIdleCallback()
{
foo->step();
}
// when initializing, in main or whatever
{
// ...
foo = &theThingIWantToCall;
glutIdleFunc(&myIdleCallback);
// ...
}
또는 :
// work these into your Core declaration
class Core {
static class Core* foo;
static void myIdleCallback() {
foo->step();
}
};
// at global scope
Core *Core::foo = NULL;
// at initialization time
{
// ...
Core::foo = &theThingIWantToCall;
// or if foo is private, add a static method to set it and call that
glutIdleFunc(&Core::myIdleCallback);
// ...
}
참고 클래스에 포인터 - 투 - 멤버 함수를 호출 "*."당신은 HTTP (A [마감]를 찾고 : //en.wikipedia.org/wiki/Closure_%28computer_science%29) (대개 * lambdas *라고 함)이며 C++ 0x의 일부입니다. 자세한 내용은 [이 질문] (http://stackoverflow.com/questions/2891690/closure-and-nested-lambdas-in-c0x)을 참조하십시오. – Mehrdad