运算符重载函数出现INTERNAL COMPILER ERROR
用的是VC++6.0,代码如下,都是书上抄的,利用友元函数实现运算符"+"的重载:
----complex.h----
#include <iostream>
using namespace std;
class complex //定义复数类
{
private:
double real,imag;
public:
complex(double r=0,double i=0) //构造函数
{
real=r;
imag=i;
}
friend complex operator + (const complex &,const complex &); //问题就出在这行,友元函数的声明
};
-----complex.cpp------
#include"complex.h"
complex operator + (const complex &a,const complex &b) //加号友元函数重载
{
return complex(a.real+b.real,a.imag+b.imag);
}
-----main.cpp------
#include"comlex.h"
int main() // 问题应该不在这里,把这个拿掉编绎问题仍然一样
{
complex c1(1,2),c2(3,4),cxres;
cxres=c1+c2;
return 0;
}
最后的错误代码完整如下:
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
example.cpp
c:\program files\microsoft visual studio\myprojects\1\complex.h(13) : 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)
网上有人说什么修改设置,可以我找不到他说的不使用头文件那一项,请教答人如何解决,谢谢了,尽量详细,不胜感激