level 1
作业班子
楼主
#include "stdlib.h"#
include "stdio.h"#include "iostream"using namespace std;class Complex{ public: Complex(){real = 0;imag = 0;} Complex(double r){real = r;imag = 0;} Complex(double r,double i){real = r;imag = i;} friend Complex operator+(Complex &,Complex &);// friend ostream & operator<<(ostream &,Complex &); private: double real; double imag; };Complex operator+(Complex &c1,Complex &c2){ return(Complex(c1.real+c2.real,c1.imag+c2.imag)); }/*ostream & operator<<(ostream &output,Complex c){ output << "(" << c.real << "," << c.imag << "i)" << endl; return output; }*/int main(){ Complex c1(3.0,4.0),c2(5,-10),c3; c3 = c1+2.5; //此处为什么不能通过编译呢?书上是这么写的// cout << c3}
2007年05月04日 13点05分
1
include "stdio.h"#include "iostream"using namespace std;class Complex{ public: Complex(){real = 0;imag = 0;} Complex(double r){real = r;imag = 0;} Complex(double r,double i){real = r;imag = i;} friend Complex operator+(Complex &,Complex &);// friend ostream & operator<<(ostream &,Complex &); private: double real; double imag; };Complex operator+(Complex &c1,Complex &c2){ return(Complex(c1.real+c2.real,c1.imag+c2.imag)); }/*ostream & operator<<(ostream &output,Complex c){ output << "(" << c.real << "," << c.imag << "i)" << endl; return output; }*/int main(){ Complex c1(3.0,4.0),c2(5,-10),c3; c3 = c1+2.5; //此处为什么不能通过编译呢?书上是这么写的// cout << c3}