#ifndef Complex_H
#define Complex_H
#include <iostream>
using namespace std;
class Complex
{ public: Complex(double a =0,double b=0);
SetComplex(double,double);
PrintComplex();
operator + (const Complex &)
private: double realpart;
double imaginarypart;
};
#endif
#include <iostream>
using namespace std;
#include "Complex.h"
Complex::Complex(double a,double b){SetComplex(a,b);}
Complex::SetComplex(double a,double b){realpart=a,imaginarypart=b;}
Complex::operator +(const Complex & a)
{ Complex d;
d.realpart=realpart+a.realpart;
d.imaginarypart=imaginarypart+a.imaginarypart;
return d;
}
Complex::PrintComplex(){cout<<realpart<<"+"<<imaginarypart<<"i"<<endl;}
double main ()
{ Complex a(1,2);
Complex b(3,5);
Complex c;
a.PrintComplex();
b.PrintComplex();
c.PrintComplex();
return 0;
}
-------------------Configuration: complex - Win32 Debug--------------------
Compiling...
complex.cpp
E:\Program Files\MSDEV98\MY PROJECT\安林\complex\complex.cpp(9) : error C2440: 'return' : cannot convert from 'class Complex' to 'int'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
E:\Program Files\MSDEV98\MY PROJECT\安林\complex\complex.cpp(18) : error C2039: 'Add' : is not a member of 'Complex'
e:\program files\msdev98\my project\安林\complex\complex.h(6) : see declaration of 'Complex'
执行 cl.exe 时出错.
complex.exe - 1 error(s), 0 warning(s)
找了半天没找到~大家帮我找找错好吗?谢谢了~
[此贴子已经被作者于2007-11-17 21:19:03编辑过]