문제

I actually have a code (which I can't change) needs a static function as "callback function".

When I change the function to static, I can't access "this" and my class members then. Also I can't pass "this" as parameter to function, again because I can't change the original SDK and definition files, so what can I do?

My code is in a class, one of class functions calls a function which needs a "static callback function" as parameter. That "callback function" needs also to access "this" and other class members to process.

What can I do? I'm using QT and VS 2012 as compiler. Thanks

도움이 되었습니까?

해결책

A static function is in common with a global function, u can't image that u can use "this" in a global function, and not to mention class members... The only difference is a static function has a "namespace" as known as the calss name. So, no matter what are you using or which compliler it is, you cannot use "this" or class members in a static function, it's just language features. And you should modify your code as Mike says.

다른 팁

If you use modern versions of C++ (11 or older) you may use std::bind. Or use boost:bind.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top