函数申明是这样的:
int Start(char *pchSmgIp, int nSmgPort, char *pchUserName, \
char *pchUserPwd, unsigned char uchVersion, int nActivtestInterval, \
void (*OnSmgMsg)(CMPP_SMGTOSP css), int nConnType, \
void (*OnLogFile)(LPCTSTR pchFmt, ...) = NULL);void OnSmgMsg(CMPP_SMGTOSP css);
然后如下使用的时候,编译老是报c2664的错误,为什么啊?
nRetCode = cmpp.Start("1",1 , "1", "1",1 ,1 , OnSmgMsg,1,);
int Start(char *pchSmgIp, int nSmgPort, char *pchUserName, \
char *pchUserPwd, unsigned char uchVersion, int nActivtestInterval, \
void (*OnSmgMsg)(CMPP_SMGTOSP css), int nConnType, \
void (*OnLogFile)(LPCTSTR pchFmt, ...) = NULL);void OnSmgMsg(CMPP_SMGTOSP css);
然后如下使用的时候,编译老是报c2664的错误,为什么啊?
nRetCode = cmpp.Start("1",1 , "1", "1",1 ,1 , OnSmgMsg,1,);
...
void OnSmgMsg(CMPP_SMGTOSP css);
???
CMPP_SMGTOSP 是一个结构体。
class A {} a;
func( int, A );
int main()
{
func( 1, 1 ); // C2664, no conversion from int to A
}
示例 2// C2664b.cpp
#include <iostream.h>
#include <string.h>class szString
{
int slen;
char *str;public:
szString(const char *);
int len() const { return slen; }
};void Test(szString &a) { cout << a.len();}szString::szString(const char * newstr)
{
slen=strlen(newstr);
str = new char[slen + 1];
strcpy(str, newstr);
}int main()
{
Test("hello"); // C2664 expected
}
可能的解决方案 再次检查给定函数的原型,并改正错误信息中指出的参数。
如果需要的话,提供显式转换。
error C2664: 'Start' : cannot convert parameter 7 from 'void (struct cmpp_smgtosp)' to 'void (__cdecl *)(struct cmpp_smgtosp)'这种我该怎么转换呢?
'function' : cannot convert parameter number from 'type1' to 'type2'The specified parameter of the specified function could not be converted to the required type. If you’ve encountered this error on code which compiled with an earlier version of Visual C++, please read Technote: Improved Conformance to ANSI C++ for more information.The following is an example of this error:class A {} a;
func( int, A );
void main()
{
func( 1, 1 ); // error, no conversion from int to A
}TipsRecheck the prototype for the given function and correct the argument noted in the error message. If necessary, an explicit conversion may need to be supplied.