From f4af5fa37bf12f93b201b432cbf9a853134fea6e Mon Sep 17 00:00:00 2001 From: Kai-Zhang Date: Mon, 14 Sep 2015 19:46:05 +0800 Subject: [PATCH] Use abstract function pointer instead of c-style casting --- sdk/ins_wrapper.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sdk/ins_wrapper.cc b/sdk/ins_wrapper.cc index 40d3ae2..0e8ecfa 100755 --- a/sdk/ins_wrapper.cc +++ b/sdk/ins_wrapper.cc @@ -10,9 +10,10 @@ extern "C" { typedef void (*SessionTimeoutCallback)(void*); typedef void (*CWatchCallback)(WatchParam*, long, SDKError); typedef void (*CTimeoutCallback)(long, void*); +typedef void (*AbstractFunc)(); struct CallbackPack { - void* callback_wrapper; + AbstractFunc callback_wrapper; long callback_id; void* ctx; }; @@ -115,7 +116,7 @@ bool SDKWatch(InsSDK* sdk, const char* key, CWatchCallback wrapper, return false; } CallbackPack* pack = new CallbackPack; - pack->callback_wrapper = (void*)(wrapper); + pack->callback_wrapper = reinterpret_cast(wrapper); pack->callback_id = callback_id; pack->ctx = context; return sdk->Watch(key, WatchCallbackWrapper, pack, error); @@ -198,7 +199,7 @@ void SDKRegisterSessionTimeout(InsSDK* sdk, SessionTimeoutCallback handle_sessio return; } CallbackPack* pack = new CallbackPack(); - pack->callback_wrapper = (void*)(handle_session_timeout); + pack->callback_wrapper = reinterpret_cast(handle_session_timeout); pack->callback_id = callback_id; pack->ctx = ctx; sdk->RegisterSessionTimeout(handle_session_timeout, ctx);