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

c++中无法运行,始终有一个异常

2012-09-28 
c++中无法运行,始终有一个错误!class Complex{private :double realdouble imagpublic :Complex(double

c++中无法运行,始终有一个错误!
class Complex
{
private :
double real;
double imag;
public :
Complex(double r = 0.0,double i = 0.0);
void print();
friend Complex operator +(Complex a,Complex b);
  friend Complex operator -(Complex a,Complex b);

};
# include "iostream"
using namespace std;
# include "Complex.h"
int main()
{
 Complex com1(5.5,6.6),com2(7.7,9.8),total;
 total = com1 + com2;
 total.print();
 total = com1 - com2;
 total.print();
  return 0;
}
Complex::Complex(double r,double i)
{
 real = r;
 imag = i;
}
Complex operator +(Complex a,Complex b)
{
 Complex temp;
 temp.real = a.real+b.real;
 temp.imag = a.imag+b.imag;
 return temp;
}
Complex operator -(Complex a,Complex b)
{
 Complex temp;
 temp.real = a.real-b.real;
 temp.imag = a.imag-b.imag;
 return temp;
}
void Complex::print()
{
 cout<<real;
 if(imag>0)
cout<<"+";
 if(imag!=0)
cout<<imag<<"i"<<endl;


}

[解决办法]
http://zhanyonhu.blog.163.com/blog/static/16186044200911631821267/?suggestedreading&wumii

我跑了下好像是fatal error C1001: INTERNAL COMPILER ERROR
楼主参考下上面的链接。。
[解决办法]
class Complex;
Complex& operator+(const Complex&,const Complex&);
Complex& operator-(const Complex&,const Complex&);

class Complex
{
private :
double real;
double imag;
public :
Complex(double r = 0.0,double i = 0.0);
void print();
friend Complex& operator+(const Complex &a,const Complex &b);
friend Complex& operator-(const Complex &a,const Complex &b);

};

Complex::Complex(double r,double i)
{
real = r;
imag = i;
}
Complex& operator+(const Complex &a,const Complex &b)
{
Complex temp;
temp.real = a.real+b.real;
temp.imag = a.imag+b.imag;
return temp;
}

Complex& operator-(const Complex &a,const Complex &b)
{
Complex temp;
temp.real = a.real-b.real;
temp.imag = a.imag-b.imag;
return temp;
}

void Complex::print()
{
cout<<real;
if(imag>0)
cout<<"+";
if(imag!=0)
cout<<imag<<"i"<<endl;
}

int main()
{
Complex com1(5.5,6.6),com2(7.7,9.8),total;
total = com1 + com2;
total.print();
total = com1 - com2;
total.print();

return 0;
}

[解决办法]
我在VC++ 6.0调试过了
[解决办法]
我刚在vs2010和vs2008下边测试运行结果正确,不会出错

热点排行