MFC程序从VC6.0移植到VS2005出现'operator +=' is ambiguous 的错误

      一个以前的VC6.0的程序,在VS2005中编译,出现了错误:'operator +=' is ambiguous  

CString  m_strDisplay;
m_strDisplay += (cDigit - IDC_0 + 0x30);

出错位置在第二句话。

    出错原因在于vs2005的编译检查比较严格,需要强制转换格式。

修改为:m_strDisplay += static_cast <char>(cDigit - IDC_0 + 0x30);

编译通过!!!


附录:

C语言中的转换:

1.隐性转换,直接赋值,例如,char  ch;int i=char;由编译器完成

2.显式转换,在变量前面加上类型(type),例如:float f;int i=(int)f

C++中的转换:

   C++继承了c语言的转换,但是这种转换并不是安全和严格的,所以C++添加了四个关键字

static_cast    用于基本的数据类型转换,指针之间的转换

char a ;
int b = static_cast<int>(a);
char c = static_cast<char>(b);
type = static_cast<test_enum>(b);

char* pa = NULL;
int *pb = (int*)pa;
//int *pb = static_cast<int*>(pa);        //error
//pa = static_cast<char*>(pb)           //error
char *pc = (char*)pb;
//char *pc = static_cast<char*>(pb);    //error

void *p = static_cast<void*>(pa);
pb = static_cast<int*>(p);
pc = static_cast<char*>(p);

dynamic_cast

const_static

reinterpret_cast

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值