P
Pmb
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:
perator+( Complex &z )
{
Complex sum;
sum.re = re + z.re;
sum.im = im + z.im;
return Complex( sum.re, sum.im );
}
Complex Complex:
perator-( Complex &z )
{
Complex diff;
diff.re = re - z.re;
diff.im = im - z.im;
return Complex( diff.re, diff.im );
}
Complex& Complex:
perator=( Complex &z )
{
re = z.re;
im = z.im;
return *this;
}
bool Complex:
perator==( 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;
}
___________________________________
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:
{
Complex sum;
sum.re = re + z.re;
sum.im = im + z.im;
return Complex( sum.re, sum.im );
}
Complex Complex:
{
Complex diff;
diff.re = re - z.re;
diff.im = im - z.im;
return Complex( diff.re, diff.im );
}
Complex& Complex:
{
re = z.re;
im = z.im;
return *this;
}
bool Complex:
{
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;
}
___________________________________