First… I have the following code in a file named core_ns.h
/*
* the prototype for the function that will be called when a connection
* is made to a listen connection.
* Arguments:
* Server_Connection - ID of the listen connection that received the request
* New_Connection - ID of the data connection that was created.
*/
typedef void (* CORE_NS_Connect_Callback)
(CORE_NS_Connection_Type Server_Connection,
CORE_NS_Connection_Type New_Connection);
I then have the following in a file named ParameterServerCSC.h
class ParameterServer{
public:
//-------------------------------------------------------------------------------
//FUNCTION: sendCallback
//
//PURPOSE: This method will be performed upon a connection with the client. The
//Display Parameter Server will be sent following a connection.
//-------------------------------------------------------------------------------
void sendCallback (CORE_NS_Connection_Type serverConnection, CORE_NS_Connection_Type newConnection);
}; // end class ParameterServer
Finally… I have the following usage in a file named ParameterServer.cpp
//-------------------------------------------------------------------------------
//FUNCTION: setup
//
//PURPOSE: This method will perform any initialization that needs to be performed
//at startup, such as initialization and registration of the server.
//-------------------------------------------------------------------------------
void ParameterServer::setup(bool isCopilotMfd){
CORE_NS_Connect_Callback newConnCallback;
newConnCallback = &ParameterServer::sendCallback;//point to local function to handle established connection.
}
I’m getting the following warning:
warning: converting from
void (ParameterServer::*)(CORE_NS_Connection_Type, CORE_NS_Connection_Type)' tovoid (*)(CORE_NS_Connection_Type, CORE_NS_Connection_Type)’
MY_PROJECT/DisplayParameterServer
ParameterServerCSC.cpp
Im using LynxOS178-2.2.2/GCC C++ compilier. My solution builds with this warning. I am trying to understand the meaning of the warnings. Any insight to this is appreciated.
ParameterServer::sendCallbackis a member function or method (its type isvoid (ParameterServer::*)(CORE_NS_Connection_Type, CORE_NS_Connection_Type)) so it cannot be used as a function (typevoid (*)(CORE_NS_Connection_Type, CORE_NS_Connection_Type)).You need to make it a static member function:
Otherwise (depending on calling convention) when the API calls
sendCallbackthe parameters will be set up incorrectly and will appear incorrect; at the very least the hiddenthisparameter will be garbage.