首先...我已經在一個文件下面的代碼名爲core_ns.hC++警告typedef void(* somename)(arg1,arg2);
/*
* 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);
然後我有一個名爲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
最後...我有文件如下在一個名爲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.
}
我得到以下警告文件中的下列用途:
警告:從
void (ParameterServer::*)(CORE_NS_Connection_Type, CORE_NS_Connection_Type)' to
空隙(*)(CORE_NS_Connection_Type,CORE_NS_Connection_Type)」
MY_PROJECT/DisplayParameterServer
ParameterServerCSC.cpp
im使用LynxOS178-2.2.2/GCC C++ compilier轉換。我的解決方案隨此警告生成。我想了解警告的含義。任何有識之士都會被讚賞。
成員函數與非成員函數不兼容,是它的要點。 – GManNickG
在編譯器實現中看起來像一個缺陷。編譯器應該發出錯誤而不是警告(IIRC GCC通常會這樣做)。正如@ ecatmur的回答指出,函數指針類型實際上是不兼容的。 –