Home › Forums › Software Development › [C++] static callback function to member function
- This topic has 3 replies, 2 voices, and was last updated 10 years, 2 months ago by Jenny [Tobii].
- AuthorPosts
- 05/08/2014 at 13:45 #1469EscallonParticipant
Hello,
I followed one of the example contained in the eyeX SDK to use a callback function as a member function of my class and not a static function.
bool EyeXHost::RegisterConnectionStateChangedHandler() { // we pass the "this" pointer as the user parameter when registering the event handler, // so that we can access it in the callback function. auto connectionStateChangedTrampoline = [](TX_CONNECTIONSTATE connectionState, TX_USERPARAM userParam) { static_cast<EyeXHost*>(userParam)->OnEngineConnectionStateChanged(connectionState); }; bool success = txRegisterConnectionStateChangedHandler( m_context, &m_connectionStateChangedTicket, connectionStateChangedTrampoline, this) == TX_RESULT_OK; return success; }
but compilation fails saying ‘txRegisterConnectionStateChangedHandler’ : cannot convert parameter 3 from ‘`anonymous-namespace’::<lambda0>’ to ‘TX_CONNECTIONSTATECHANGEDCALLBACK’
I wonder if something is missing in the example ? Maybe the is another way to do that… I use QtCreator with Qt5.3 and MVSC2010 compiler.
Thanks you
05/08/2014 at 15:12 #1470Jenny [Tobii]ParticipantHi Escallon,
It seems it may be a bug in the implementation of lambda expressions in the MSVC 2010 redistributable: https://connect.microsoft.com/VisualStudio/feedback/details/572138
That bug report is marked as closed, but there is no information about in which version the fix was included. Maybe you could try downloading the latest MSVC 2010 redist and see if that helps.
05/08/2014 at 15:38 #1471EscallonParticipantOk thanks,
I will take a look on it.
Also, Why both of the C++ examples given in the SDK use C entities like TX_CONNECTIONSTATECHANGEDCALLBACK instead of ConnectionStateChangedCallback, found in EyeXClientTypes.h :namespace Tx {
typedef std::function<void (TX_CONNECTIONSTATE)>
ConnectionStateChangedCallback;
}?
That’s might be useful to avoid this error.
Is there a 100% C++ example/doc available ?Best regards
06/08/2014 at 13:35 #1473Jenny [Tobii]ParticipantHi Escallon,
Yes, the current C/C++ samples are written using the C API directly. It was important for us initially to have the C API exercised as much as possible so we could find areas of improvement and simplification.
But now it is definately on our todo list to have a new take on the C/C++ SDK and write samples using the C++ binding. Inspired by the .NET SDK we have developed since, we will probably extract and expand common functionality into a separate EyeXFramework for C++ and provide some code integrating EyeX into one or two specific C++ GUI frameworks.
- AuthorPosts
- You must be logged in to reply to this topic.