| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1597 人关注过本帖
标题:这么多错误??????
只看楼主 加入收藏
幽灵嫖客
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-1-15
收藏
 问题点数:0 回复次数:7 
这么多错误??????

这是头文件:
#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)

各位帮我看看,谢谢了!

搜索更多相关主题的帖子: complex double const std opreator 
2007-05-05 06:10
幽灵嫖客
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-1-15
收藏
得分:0 
回复:(幽灵嫖客)这么多错误??????
错误多,好像很多相似的!

C primer plus
2007-05-05 06:13
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 
以下是引用幽灵嫖客在2007-5-5 6:13:28的发言:
错误多,好像很多相似的!

细心一点吧,你看你错了些什么:
1,operator是这样拼写的。
2,类定义外的大括号“;”忘记了。
3,实现里,默认参数是不加的,只在声明里加上。


粗略看了下,可能还有,不过先改过来吧,这些都是不细心造成的!


Fight  to win  or  die...
2007-05-05 10:30
幽灵嫖客
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-1-15
收藏
得分:0 

郁闷亚,看起来挺简单的!做起来就不一样了!


C primer plus
2007-05-05 14:48
neverDie
Rank: 1
等 级:新手上路
威 望:1
帖 子:123
专家分:0
注 册:2007-5-5
收藏
得分:0 
opreator

operator

2007-05-05 16:50
weishj
Rank: 1
等 级:新手上路
威 望:2
帖 子:141
专家分:0
注 册:2007-4-22
收藏
得分:0 
楼主也太马虎了
好多拼写错误,函数在类声明中的形参老整的与其实现中的形参不同
下面是改了以后的,看下哪地方跟你的不同吧
/************************** complex.h ***********************************/
#include <iostream>
using namespace std;
#ifndef COMPLEX0_H_
#define COMPLEX0_H_
class complex
{
private:
double real;
double imaginary;
public:
complex(double r,double i);
complex operator +(const complex& c);
complex operator *(const complex& c);
friend complex operator *(double x,const complex& c );
};
#endif
/****************************************** complex.cpp ************************/
#include <iostream>
using namespace std;
#include "complex.h"
complex::complex(double r,double i)
{
real=r;
imaginary=i;
}
complex complex::operator+(const complex &c)
{
return complex(real+c.real,imaginary+c.imaginary);
}
complex complex::operator*(const complex& x)
{
return complex(real*x.real,imaginary*x.imaginary);
}
complex operator*(double x,const complex &c)
{
return complex(0.0,c.imaginary*x);
//或者return complex(c.real*x,0.0);
//看你重载的目的了
}

If you shed tears when you miss the sun, you also miss the stars.
2007-05-05 22:58
幽灵嫖客
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-1-15
收藏
得分:0 

各位见笑了!


C primer plus
2007-05-05 23:15
快速回复:这么多错误??????
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015254 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved