首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

程序出错,找不到是什么原回,在家给看看,该怎么处理

2012-01-13 
程序出错,找不到是什么原回,在家给看看调试时出错指向此处好像是MFC中的文件,“strcore.cpp 好像是重载+吧

程序出错,找不到是什么原回,在家给看看
调试时出错指向此处   好像是MFC中的文件,“strcore.cpp "   好像是重载+吧
CString   AFXAPI   operator+(const   CString&   string1,   const   CString&   string2)
{
CString   s;
s.ConcatCopy(string1.GetData()-> nDataLength,   string1.m_pchData,
string2.GetData()-> nDataLength,   string2.m_pchData);
return   s;
}
我的程序中用到了例如
CSting   sp;
sp=sp+ "123 ";
是什么原因造成出错的,大家帮帮,先谢了。


[解决办法]
sp=sp+ "123 ";
操作符+的两个操作对象都是CString,而你的“123”不是CString
[解决办法]
先定义一个CString对象str,然后 "123 " 赋给str.接下来就可以调用重载操作符 "+ "了!!!!!!
[解决办法]
What is version of your IDE? What is the error message?

Per my test, If I debug your code in VC6.0, the override operator will not be invoked; however the code worked fine.
If I call the code like this:
CSting sp;
sp=sp+CString( "123 ");
The override operator was invoked and also worked fine;

In VC8.0, your writings is not supported yet. The correct way should be as follows:
CString AFXAPI operator+(const CString& string1, const CString& string2)
{
CString s;
s.Insert(0,string1.GetString());
s.Insert(string1.GetLength(),string2.GetString());
return s;
}


热点排行