L
Leszek Tumm
Hi.
Can you help solve a problem with operator overloading ?
in one file i have definition of my class and declarations of overloaded
operators:
class Complex
{
long double Re;
long double Im;
public:
friend const Complex operator+ (const Complex &, const Complex &);
//..//
};
Second file contains definition of operator+ :
const Complex operator+ (const Complex & x, const Complex & y)
{
return Complex(x.Re + y.Re, x.Im + y.Im);
}
I don't know why but i'm getting these error messages:
complex.h: In function `const Cmpl::Complex operator+(const Cmpl::Complex&,
const Cmpl::Complex&)':
complex.h:20: `long double Cmpl::Complex::Re' is private
complex.cpp:34: within this context
complex.h:20: `long double Cmpl::Complex::Re' is private
complex.cpp:34: within this context
complex.h:21: `long double Cmpl::Complex::Im' is private
complex.cpp:34: within this context
complex.h:21: `long double Cmpl::Complex::Im' is private
complex.cpp:34: within this context
line 34 is:
return Complex(x.Re + y.Re, x.Im + y.Im);
What is the reason of this error? What should I do to make it
compile properly??
Thanks.
Leszek
Can you help solve a problem with operator overloading ?
in one file i have definition of my class and declarations of overloaded
operators:
class Complex
{
long double Re;
long double Im;
public:
friend const Complex operator+ (const Complex &, const Complex &);
//..//
};
Second file contains definition of operator+ :
const Complex operator+ (const Complex & x, const Complex & y)
{
return Complex(x.Re + y.Re, x.Im + y.Im);
}
I don't know why but i'm getting these error messages:
complex.h: In function `const Cmpl::Complex operator+(const Cmpl::Complex&,
const Cmpl::Complex&)':
complex.h:20: `long double Cmpl::Complex::Re' is private
complex.cpp:34: within this context
complex.h:20: `long double Cmpl::Complex::Re' is private
complex.cpp:34: within this context
complex.h:21: `long double Cmpl::Complex::Im' is private
complex.cpp:34: within this context
complex.h:21: `long double Cmpl::Complex::Im' is private
complex.cpp:34: within this context
line 34 is:
return Complex(x.Re + y.Re, x.Im + y.Im);
What is the reason of this error? What should I do to make it
compile properly??
Thanks.
Leszek