关于c2664的错误问题?

adule 2004-12-17 10:11:21
函数申明是这样的:
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,);
...全文
1039 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2004-12-17
  • 打赏
  • 举报
回复
或用强制类型转换一下
oyljerry 2004-12-17
  • 打赏
  • 举报
回复
类型不对,检查一下
bohut 2004-12-17
  • 打赏
  • 举报
回复
没有你全部的代码,不太好说,给你MSDN上对这一错误的解释,希望对你有所帮助

编译器错误 C2664“function”: 不能将参数 number 从“type1”转换为“type2”

某参数无法转换为所需类型。如果创建某个类的实例,然后试图对用 explicit 关键字标记的构造函数进行隐式转换,则可能发生此错误。

如果将临时对象传递给采用指向对象的引用作为参数的函数,则该引用必须是常数引用。

如果使用不是函数所预期的类型的参数调用该函数,则使用适当的构造函数创建临时对象。然后将该临时对象传递给函数。在这种情况下,该临时对象用于初始化引用。在该语言的早期版本中,所有的引用都可以由临时对象进行初始化。此行为现在已被逐步淘汰,因此 Microsoft C/C++ 编译器给出该错误。

下面的代码通过调用带有字符串的 Test 演示此错误。因为该参数是 szString 引用,所以必须使用适当的构造函数创建对象。结果是一个无法用于初始化该引用的临时对象。

示例 1

// C2664a.cpp
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
}
可能的解决方案

再次检查给定函数的原型,并改正错误信息中指出的参数。
如果需要的话,提供显式转换。

adule 2004-12-17
  • 打赏
  • 举报
回复
???
adule 2004-12-17
  • 打赏
  • 举报
回复
nRetCode = cmpp.Start("1",1 , "1", "1",1 ,1 , OnSmgMsg,1,"");
CMPP_SMGTOSP 是一个结构体。
老夏Max 2004-12-17
  • 打赏
  • 举报
回复
楼上正解!
呵呵,默认参数前不需要“,”
bohut 2004-12-17
  • 打赏
  • 举报
回复
CMPP_SMGTOSP怎么定义的?

nRetCode = cmpp.Start("1",1 , "1", "1",1 ,1 , OnSmgMsg,1,);

---》

nRetCode = cmpp.Start("1",1 , "1", "1",1 ,1 , OnSmgMsg,1);

DentistryDoctor 2004-12-17
  • 打赏
  • 举报
回复
void (*OnSmgMsg)(CMPP_SMGTOSP css), int nConnType, \
...
void OnSmgMsg(CMPP_SMGTOSP css);
???
bobob 2004-12-17
  • 打赏
  • 举报
回复
nRetCode = cmpp.Start("1",1 , "1", "1",1 ,1 , &OnSmgMsg,1);
asd123yx 2004-12-17
  • 打赏
  • 举报
回复
Compiler Error C2664
'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
}

Tips

Recheck 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.
adule 2004-12-17
  • 打赏
  • 举报
回复
错误如下:
error C2664: 'Start' : cannot convert parameter 7 from 'void (struct cmpp_smgtosp)' to 'void (__cdecl *)(struct cmpp_smgtosp)'

这种我该怎么转换呢?

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧