fatal error C1001: INTERNAL COMPILER ERROR 小弟我是初学者 求大神抽时间帮忙看看

Hi_BaBy 发布于 2012/04/28 17:41
阅读 891
收藏 0
#include<iostream>
using namespace std;
class Complex
{
public: 
Complex(double r=0.0,double i=0.0)
{real=r;image=i;} 
friend Complex operator + (Complex c1,Complex c2);
    friend Complex operator - (Complex c1,Complex c2);
void display();
private:
double real; //复数实部
double image; //复数虚部
};
Complex operator + (Complex c1,Complex c2)
{
Complex c;
    c.real=c1.real+c2.real;
c.image=c1.image+c2.image;
return c;
}
Complex Complex:: operator - (Complex c2)
{
return Complex( c1.real-c2.real,c1.image-c2.image);
}
void Complex::display( )
{
if(image>0)
cout<<real<<'+'<<image<<'i';
else
cout<<real<<image<<'i';
}
int main()
{
double real,image;
cin>>real>>image;
    Complex c1(real,image);
cin>>real>>image;
    Complex c2(real,image);
Complex c3;
    c3=c1+c2;
c3.display();
c3=c1-c2;
c3.display();
return 0;
} 
加载中
0
PYPlus
PYPlus

似乎是+的定义部分错了,

Complex Complex:: operator + (Complex c1,Complex c2)
16	{
17	Complex c;
18	    c.real=c1.real+c2.real;
19	c.image=c1.image+c2.image;
20	return c;
21	}

c是局部变量return一下被销毁了,你还丢了Complex::

-的定义部分的型参与声明的型参个数不对。



Hi_BaBy
Hi_BaBy
+部分没问题 我在main函数中进行了赋值
返回顶部
顶部