質問

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