这是头文件:
#include <iostream>
using namespace std;
#ifndef COMPLEX0_H_
#define COMPLEX0_H_
class complex
{
private:
double real;
double imaginary;
public:
complex(double r=0.0,double i=0.0);
complex opreator+(const complex & c)const;
complex opreator*(const complex & c)const;
friend complex opreator*(double x,const compelx & c );
}
#endif
下面是成员函数的实现文件:
#include <iostream>
using namespace std;
#include "complex0.h"
complex::complex(double r=0.0,double i=0.0)
{
real=r;
imaginary=i;
}
complex complex::opreator+(const complex &c)const
{
return complex(real+c.real,imaginary+c.imaginary);
}
complex complex::opreator*(double x)const
{
return complex(real*x,imaginary*x);
}
complex opreator*(double x,const complex &c)
{
return c*x;
}
这只是一部分功能,就编译这些错误就一大堆,比如:
:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(12) : error C2143: syntax error : missing ';' before '+'
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(12) : error C2460: 'opreator' : uses 'complex', which is being defined
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(6) : see declaration of 'complex'
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(12) : error C2059: syntax error : '+'
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(12) : error C2238: unexpected token(s) preceding ';'
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(15) : error C2143: syntax error : missing ';' before '*'
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(15) : error C2460: 'opreator' : uses 'complex', which is being defined
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(6) : see declaration of 'complex'
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(15) : error C2086: 'opreator' : redefinition
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(15) : error C2062: type 'double' unexpected
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(15) : error C2238: unexpected token(s) preceding ';'
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(16) : error C2143: syntax error : missing ';' before '*'
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(16) : error C2460: 'opreator' : uses 'complex', which is being defined
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(6) : see declaration of 'complex'
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(16) : error C2433: 'opreator' : 'friend' not permitted on data declarations
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(16) : error C2244: 'opreator' : unable to resolve function overload
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(16) : error C2062: type 'double' unexpected
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(16) : error C2238: unexpected token(s) preceding ';'
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(5) : error C2533: 'complex::complex' : constructors not allowed a return type
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(5) : error C2572: 'complex::complex' : redefinition of default parameter : parameter 2
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(11) : see declaration of 'complex::complex'
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(5) : error C2572: 'complex::complex' : redefinition of default parameter : parameter 1
d:\vc++ 6.0\msdev98\myprojects\my c plus\类\complex0.h(11) : see declaration of 'complex::complex'
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(9) : error C2143: syntax error : missing ';' before '+'
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(9) : error C2350: 'complex::opreator' is not a static member
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(9) : error C2264: 'complex::complex' : error in function definition or declaration; function not called
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(9) : error C2143: syntax error : missing ';' before '+'
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(10) : error C2143: syntax error : missing ';' before '{'
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(10) : error C2447: missing function header (old-style formal list?)
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(21) : error C2143: syntax error : missing ';' before '*'
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(21) : error C2350: 'complex::opreator' is not a static member
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(21) : error C2264: 'complex::complex' : error in function definition or declaration; function not called
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(21) : error C2062: type 'double' unexpected
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(22) : error C2143: syntax error : missing ';' before '{'
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(22) : error C2447: missing function header (old-style formal list?)
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(25) : error C2143: syntax error : missing ';' before '*'
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(25) : error C2264: 'complex::complex' : error in function definition or declaration; function not called
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(25) : error C2062: type 'double' unexpected
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(26) : error C2143: syntax error : missing ';' before '{'
D:\VC++ 6.0\MSDev98\MyProjects\My C Plus\类\complex0.cpp(26) : error C2447: missing function header (old-style formal list?)
执行 cl.exe 时出错.
complex0.obj - 1 error(s), 0 warning(s)
各位帮我看看,谢谢了!