2 hwqiang hwqiang 于 2013.12.27 00:28 提问

函数转换时碰到问题,未破,求助各位朋友,非常感谢!!!

编译时的错误提示:

 pmd/pmdEDU.cpp: In function ‘int (* getEntryFuncByType(EDU_TYPES))(pmdEDUCB*, void*)’:
pmd/pmdEDU.cpp:94:4: error: invalid conversion from ‘int (*)(pmdEDUCB, void*)’ to ‘pmdEntryPoint {aka int (*)(pmdEDUCB*, void*)}’ [-fpermissive]
    } ;

其中函数的声明及实现如下:

头文件中声明:
pmdEDU.hpp

typedef int (*pmdEntryPoint) ( pmdEDUCB *, void * ) ;
pmdEntryPoint getEntryFuncByType ( EDU_TYPES type ) ;

int pmdAgentEntryPoint ( pmdEDUCB *cb, void *arg ) ;

pmdEDU.cpp文件中实现代码如下:

struct _eduEntryInfo
{
   EDU_TYPES type ;
   int regResult ;
   pmdEntryPoint entryFunc ;
} ;
define ON_EDUTYPE_TO_ENTRY1(type,system,entry,desp) \
{ type, registerEDUName(type,desp,system), entry }

pmdEntryPoint getEntryFuncByType ( EDU_TYPES type )
{
   pmdEntryPoint rt = NULL ;
   static const _eduEntryInfo entry[] = {
      ON_EDUTYPE_TO_ENTRY1 ( EDU_TYPE_AGENT, false,
                             pmdAgentEntryPoint,
                             "Agent" ),
      ON_EDUTYPE_TO_ENTRY1 ( EDU_TYPE_TCPLISTENER, true,
                             pmdTcpListenerEntryPoint,
                             "TCPListener" ),
      ON_EDUTYPE_TO_ENTRY1 ( EDU_TYPE_MAXIMUM, false,
                             NULL,
                             "Unknown" )
   } ;
   static const unsigned int number = sizeof ( entry ) /
                                      sizeof ( _eduEntryInfo ) ;
   unsigned int index = 0 ;
   for ( ; index < number; ++index )
   {
      if ( entry[index].type == type )
      {
         rt = entry[index].entryFunc ;
         goto done ;
      }
   }
done :
   return rt ;
}

编译环境:debian sid g++4.8.2

我没发现问题出现在哪儿,烦劳各位了

1个回答

oyljerry
oyljerry   Ds   Rxr 2014.12.28 15:34

函数指针转换时,类型有点对不上,错误信息提示你了

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!