问题描述
- 函数转换时碰到问题,未破,求助各位朋友,非常感谢!!!
-
编译时的错误提示: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.hpptypedef 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
我没发现问题出现在哪儿,烦劳各位了
解决方案
函数指针转换时,类型有点对不上,错误信息提示你了
时间: 2024-09-12 03:44:53