C++操作符重载的问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 11:29:22
#include <iostream>
using namespace std;
class mypoint
{int x,y;
public:
mypoint(){};
mypoint(int px,int py){x=px;y=py;}
void view(){cout<<"("<<x<<","<<y<<")"<<endl;}
friend mypoint operator +(mypoint &p1,mypoint &p2)
{
return mypoint(p1.x+p2.x,p1.y+p2.y);
}
};
void main()
{
mypoint p1(10,10),p2(20,20),p3;
p3=p1+p2;
p3.view();
(p1+p2).view();
}
编译出错:\Documents and Settings\Administrator\Cpp2.cpp(10) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
执行 cl.exe 时出错.
-----------------------------------------------------------------
为什么改成如下就能运行成功:
#include <iost

就你的第一个Visual C++ 2005下面编译无错误提示:
------ 已启动生成: 项目: node, 配置: Release Win32 ------
正在编译...
main.cpp
正在链接...
正在生成代码
已完成代码的生成
正在嵌入清单...
生成日志保存在“file://e:\Documents\Visual Studio 2005\Projects\node\node\Release\BuildLog.htm”
node - 0 个错误,0 个警告
========== 生成: 1 已成功, 0 已失败, 0 最新, 0 已跳过 ==========

结果是你要的吗?
(30,30)
(30,30)
请按任意键继续. . .