令人困惑的编译错误 [英] Confusing compile error

查看:141
本文介绍了令人困惑的编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑,我得到的编译器错误信息是引用

到。有人可以采取一个雄鹅,让我知道我做错了什么?该计划

如下。当我编译它时,我得到以下错误


______________________________

Borland C ++ 5.5.1 for Win32版权所有(c)1993,2000 Borland

d:\ temp \ complex {\\ temp.cpp:

错误E2333 d:\ temp\complex\temp.cpp 73:班级成员

''复杂::共轭(复杂)''在其类外宣布

错误E2040 d:\ temp \ complex {\\ temp.cpp 74:声明终止不正确

*** 2编译错误***


工具已完成,退出代码为1

______________________________


我是否搞砸了确定

的功能___________________________________

#include< iostream.h>

#include < math.h>


class Complex {

friend ostream& operator<<(ostream&,Complex&);

public:

Complex(float = 0.0,float = 0.0);

复杂的算子+(复杂&);

复杂的算子 - (复杂& );

Complex& operator =(Complex&);

bool operator ==(Complex&);

private:

复共轭(复数);

浮点数(复数);

浮动重新;

浮动im; < br $>
};


ostream& operator<<(ostream& output,Complex& z)

{

float x = z.re,y = z.im;


if(y == 0)// z = a

输出<< x;

else if(x == 0&& y> 0)// z = i b

output<< i << y;

else if(x == 0&& y< 0)// z = - i b

output<< - i << -y;

else if(x> 0&& y> 0)// z = a + i b

输出<< x<< " + i << z.im;

else if(x> 0&& y< 0)// z = a - i b

output<< x<< " - 我 << -y;


返回输出;

}


Complex :: Complex(float a,float b)

:re(a),im(b){}


Complex Complex :: operator +(Complex& z)

{

复数总和;


sum.re = re + z.re;

sum.im = im + z .im;


返回复杂(sum.re,sum.im);

}


复杂复合体:: operator-(Complex& z)

{

复杂差异;


diff.re = re - z。 re;

diff.im = im - z.im;


返回Complex(diff.re,diff.im);

}


复杂& Complex :: operator =(Complex& z)

{

re = z.re;

im = z.im;


返回* this;

}


bool Complex :: operator ==(Complex& z)

{

return(re == z.re&& im == z.im);

}


Complex Complex :: conjugate(Complex z);

{

返回Complex(z.re,-z.im);

}


浮点数Complex :: magnitude(复杂z)

{

float x = z.re, y.im;


返回sqrt(x * x + y * y);

}


int main()

{

复杂z(3,4);


cout<< z = << z<< endl;

cout<< z * = <<共轭(z)<< endl:


返回0;

}


___________________________________

解决方案

" Pmb" <所以***** @ somewhere.com>写了...

我很困惑我得到的编译器错误消息是什么引用
。有人可以采取一个雄鹅,让我知道我做错了什么?
计划如下。当我编译它时,我得到以下错误

______________________________
Borland C ++ 5.5.1 for Win32版权所有(c)1993,2000 Borland
d:\ temp \ complexx \\ temp.cpp:
错误E2333 d:\ temp \ complexx \ temp.cpp 73:类成员
''Complex :: conjugate(Complex)''在其类之外声明
错误E2040 d:\ temp \ complex {\\ temp.cpp 74:声明终止
错误*** 2编译中的错误***

工具已完成,退出代码为1
______________________________

我搞砸了确定


[...]

复杂情结的功能: :共轭物(Complex z);
^^^^

那里有什么,在行尾?

{
返回Complex(z.re, -z.im);
}




Victor


" Pmb" <所以***** @ somewhere.com>写道...


Victor Bazarov <五******** @ comAcast.net>在消息中写道
新闻:xAQtc.3032


3x.2476@attbi_s54 ...

" Pmb" <所以***** @ somewhere.com>写道...

我很困惑我所得的编译器错误消息是指的是什么。有人可以采取一个雄鹅,让我知道我做错了什么?


程序

如下所示。当我编译它时,我得到以下错误

______________________________
Borland C ++ 5.5.1 for Win32版权所有(c)1993,2000 Borland
d:\ temp \ complexx \\ temp.cpp:
错误E2333 d:\ temp \ complexx \ temp.cpp 73:类成员
''Complex :: conjugate(Complex)''在其类之外声明
错误E2040 d:\ temp \ complex {\\ temp.cpp 74:声明已终止


*** 2编译错误***

工具已完成退出代码1
______________________________

我是否搞砸了确定


的功能[... ]

复杂复杂::共轭(复杂z);


^^^^
那里有什么,在结束时这条线?

{
返回Complex(z.re,-z.im);
}



很抱歉,但我不知道你的意思是什么。请更准确。




删除分号。


I''m confused as to what the compiler error message I''m getting is refering
to. Can someone take a gander and let me know what I did wrong? The program
is below. When I compile it I get the following error

______________________________
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
d:\temp\complex\temp.cpp:
Error E2333 d:\temp\complex\temp.cpp 73: Class member
''Complex::conjugate(Complex)'' declared outside its class
Error E2040 d:\temp\complex\temp.cpp 74: Declaration terminated incorrectly
*** 2 errors in Compile ***

Tool completed with exit code 1
______________________________

Did I screw up with the function which determines the

___________________________________
#include <iostream.h>
#include <math.h>

class Complex {
friend ostream &operator<<( ostream &, Complex & );
public:
Complex( float = 0.0, float = 0.0 );
Complex operator+( Complex & );
Complex operator-( Complex & );
Complex &operator=( Complex & );
bool operator==( Complex & );
private:
Complex conjugate( Complex );
float magnitude( Complex );
float re;
float im;
};

ostream &operator<<( ostream &output, Complex &z )
{
float x = z.re, y = z.im;

if ( y == 0 ) // z = a
output << x;
else if ( x == 0 && y > 0 ) // z = i b
output << "i " << y;
else if ( x == 0 && y < 0 ) // z = - i b
output << "- i " << -y;
else if ( x > 0 && y > 0 ) // z = a + i b
output << x << " + i " << z.im;
else if ( x > 0 && y < 0 ) // z = a - i b
output << x << " - i " << -y;

return output;
}

Complex::Complex( float a, float b )
: re( a ), im( b) { }

Complex Complex::operator+( Complex &z )
{
Complex sum;

sum.re = re + z.re;
sum.im = im + z.im;

return Complex( sum.re, sum.im );
}

Complex Complex::operator-( Complex &z )
{
Complex diff;

diff.re = re - z.re;
diff.im = im - z.im;

return Complex( diff.re, diff.im );
}

Complex& Complex::operator=( Complex &z )
{
re = z.re;
im = z.im;

return *this;
}

bool Complex::operator==( Complex &z )
{
return ( re == z.re && im == z.im );
}

Complex Complex::conjugate( Complex z );
{
return Complex( z.re, -z.im);
}

float Complex::magnitude( Complex z )
{
float x = z.re, y.im;

return sqrt( x*x + y*y );
}

int main()
{
Complex z( 3, 4 );

cout << "z = " << z << endl;
cout << "z* = " << conjugate( z ) << endl:

return 0;
}

___________________________________

解决方案

"Pmb" <so*****@somewhere.com> wrote...

I''m confused as to what the compiler error message I''m getting is refering
to. Can someone take a gander and let me know what I did wrong? The program is below. When I compile it I get the following error

______________________________
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
d:\temp\complex\temp.cpp:
Error E2333 d:\temp\complex\temp.cpp 73: Class member
''Complex::conjugate(Complex)'' declared outside its class
Error E2040 d:\temp\complex\temp.cpp 74: Declaration terminated incorrectly *** 2 errors in Compile ***

Tool completed with exit code 1
______________________________

Did I screw up with the function which determines the
[...]
Complex Complex::conjugate( Complex z ); ^^^^
What''s that there, at the end of the line?
{
return Complex( z.re, -z.im);
}



Victor


"Pmb" <so*****@somewhere.com> wrote...


"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:xAQtc.3032


3x.2476@attbi_s54...

"Pmb" <so*****@somewhere.com> wrote...

I''m confused as to what the compiler error message I''m getting is refering to. Can someone take a gander and let me know what I did wrong? The


program

is below. When I compile it I get the following error

______________________________
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
d:\temp\complex\temp.cpp:
Error E2333 d:\temp\complex\temp.cpp 73: Class member
''Complex::conjugate(Complex)'' declared outside its class
Error E2040 d:\temp\complex\temp.cpp 74: Declaration terminated


incorrectly

*** 2 errors in Compile ***

Tool completed with exit code 1
______________________________

Did I screw up with the function which determines the



[...]

Complex Complex::conjugate( Complex z );


^^^^
What''s that there, at the end of the line?

{
return Complex( z.re, -z.im);
}



Sorry but I have no idea what you''re point is. Please be more precise.



Remove the semicolon.


这篇关于令人困惑的编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆