首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++警告类型胡枝子(* somename) (arg1,arg2);

C++警告类型胡枝子(* somename) (arg1,arg2);
EN

Stack Overflow用户
提问于 2012-08-23 17:13:34
回答 1查看 134关注 0票数 0

首先..。我在一个名为core_ns.h的文件中有以下代码

代码语言:javascript
复制
/*
 * 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的文件中得到以下内容

代码语言:javascript
复制
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的文件中有以下用法

代码语言:javascript
复制
       //-------------------------------------------------------------------------------
      //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)' tovoid (*)(CORE_NS_Connection_Type,CORE_NS_Connection_Type)‘ MY_PROJECT/DisplayParameterServer ParameterServerCSC.cpp

我使用LynxOS178 178-2.2.2/GCC C++ compilier。我的解决方案建立在这个警告之上。我正在努力理解这些警告的含义。对此的任何见解都是值得赞赏的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-23 17:16:08

ParameterServer::sendCallback是一个成员函数或方法(其类型为void (ParameterServer::*)(CORE_NS_Connection_Type, CORE_NS_Connection_Type)),因此不能用作函数(void (*)(CORE_NS_Connection_Type, CORE_NS_Connection_Type)类型)。

您需要使它成为一个静态成员函数:

代码语言:javascript
复制
static void sendCallback (CORE_NS_Connection_Type serverConnection, CORE_NS_Connection_Type newConnection);

否则(取决于调用约定),当API调用sendCallback时,参数将被错误地设置并显示为不正确;至少隐藏的this参数将是垃圾。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12096851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档