重載運算符為友元函數時出錯!!!! 急 在線等
可以重載為成員函數,但是當我重載為友元函數時就出錯.. 不知道哪們大蝦幫忙解釋一下.以下是出錯信息:
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
E:\VC\VC6CN\COMMON\MSDEV98\BIN\1\1.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 时出错.
1.exe - 1 error(s), 0 warning(s)
以下是程序:
#include<iostream>
using namespace std;
class Vector1
{
int x,y;
public:
Vector1() { };
Vector1(int x1,int y1) { x=x1; y=y1; }
friend Vector1 operator +(Vector1 v1,Vector1 v2) //提示這裡有錯..
{ Vector1 tmp;
tmp.x=v1.x+v2.x;
tmp.y=v1.y+v2.y;
return tmp;
}
void disp()
{ cout<<"("<<x<<","<<y<<")"<<endl;
}
};
void main()
{ Vector1 v1(6,8),v2(3,6),v3;
v3=v1+v2;
cout<<"v1+v2=";
v3.disp();
}