complex.cpp文件,错误提示:unexpected end of file while looking for precompiled header directive ||complex.cpp文件为什么build不过
//下面是complex.cpp
#include <iostream.h>
#include <math.h>
#include <Complex.h>
friend ostream& operator << ( ostream& os, complex & ob )
{
//友元函数:重载<<,将复数ob输出到输出流对象os中。
return os << ob.Re << ( ob.Im >= 0.0 ) ? “+” : “-”
<< fabs ( ob.Im ) << “i”;
}
complex& complex ::operator + ( complex & ob )
{
//重载函数:复数加法运算。
complex * result = new complex ( Re + ob.Re, Im + ob.Im );
return * result;
}
complex& complex :: operator – ( complex& ob )
{
//重载函数:复数减法运算
complex * result = new complex ( Re – ob.Re, Im – ob.Im );
return * result;
}
complex& complex :: operator * ( complex& ob )
{
//重载函数:复数乘法运算
complex * result =
new complex ( Re * ob.Re – Im * ob.Im, Im * ob.Re + Re * ob.Im );
return * result;
}
complex& complex :: operator / ( complex& ob )
{
//重载函数:复数除法运算
double d = ob.Re * ob.Re + ob.Im * ob.Im;
complex * result = new complex ( ( Re * ob.Re + Im * ob.Im ) / d,
( Im * ob. Re – Re * ob.Im ) / d );
return * result;
}
//结束
//下面是 Complex.h
#ifndef _complex_h_
#define _complex_h_
#include <iostream.h>
class complex
{
private:
double Re ; //复数的实部
double Im; //复数的虚部
//不带参数的构造函数
public:
complex(){ Re = Im = 0 ; }
//只置实部的构造函数
complex( double r ){ Re = r ; Im = 0 ; }
//分别置实部、虚部的构造函数
complex( double r , double i ){ Re = r ; Im = i ; }
//取复数实部
double getReal ( ) { return Re; }
//取复数虚部
double getImag ( ) { return Im; }
//修改复数实部
void setReal ( double r ) { Re = r; }
//修改复数虚部
void setImag ( double i ) { Im = i; }
//复数赋值
complex& operator = ( complex& ob ){ Re = ob.Re ; Im = ob.Im ; }
//重载函数:加
complex& operator + ( complex& ob );
//重载函数:减
complex& operator - ( complex& ob );
//重载函数:成
complex& operator * ( complex& ob );
//重载函数:除
complex& operator / ( complex& ob );
//友元函数:重载<< 输出
friend ostream& operator << ( ostream& os , complex& c );
};
#endif