[Qt-interest] static function emitting signal
Colin S. Miller
no-spam-thank-you at csmiller.demon.co.uk
Wed Mar 24 23:50:56 CET 2010
Gabriel M. Beddingfield wrote:
>
> A lot of callback API's will do something like this:
>
> typedef void (*SomeCallbackType)(void* arg);
> int register_callback(SomeCallbackType function, void* arg);
>
> the 'arg' is a handle to... anything you want. When wrapping this sort
> of callback API in C++, it's common to do this:
>
> class Foo {
> public:
> Foo() {}
>
> static void _callback(void* arg) {
> Foo* that = static_cast<Foo*>(arg);
> that->my_callback();
> }
>
> protected:
> void my_callback() {
> // Do your real work here
> }
> };
>
> int main()
> {
> Foo f;
> register_callback(Foo::_callback, &f);
>
> //...
> }
>
Shouldn't static_cast be reinterpret_cast ?
Colin S. Miller
--
Replace the obvious in my email address with the first three letters of the hostname to reply.
More information about the Qt-interest-old
mailing list