eduard77 -3 Junior Poster

I try to make an exercise that involves classes. I reached until this point

#include <iostream>
#include<math.h>
#include<iomanip>
#include<conio.h>

using namespace std;
class Cplx {
double re, im;
public:
	//constructors
	Cplx(double x=0, double y=0);
	Cplx(const Cplx& z);
	//accessing the members
	double real() const {return re;}
	double imag() const {return im;}
	//setting the members
	void setreal(double x) {re=x;}
	void setimag(double y) {im = y;}
	//simple attribution
	Cplx& operator+=(const Cplx& z);
	Cplx& operator-=(const Cplx& z);
	Cplx& operator*=(const Cplx& z);
	Cplx& operator/=(const Cplx& z);
	//module and argument
	double mod (const Cplx z);
	double arg (const Cplx z);
	//input/output
	friend istream& operator>>(istream& is, Cplx& z);
	friend ostream& operator>>(ostream& is, const Cplx& z);
	//binary operators
	friend int operator  == (const Cplx& s, const Cplx& d);
	friend int operator  != (const Cplx& s, const Cplx& d);
	friend int operator  + (const Cplx& s, const Cplx& d);
	friend int operator  - (const Cplx& s, const Cplx& d);
	friend int operator  * (const Cplx& s, const Cplx& d);
	friend int operator  / (const Cplx& s, const Cplx& d);
	//unary operators
	friend Cplx operator -(const Cplx& z);
	friend Cplx operator !(const Cplx& z); //conjugat
	friend Cplx operator ++(const Cplx& z); //prefix
	friend Cplx operator ++( Cplx& z, int); //postfix
};
//implementing the class
Cplx::Cplx(double x, double y) {
re=x;
im=y;
}
Cplx::Cplx(const Cplx& z) {
	re= z.real();
	im= z.imag();

}
Cplx& Cplx::operator=(const Cplx& z){
	if(&z != this) {
	re= z.real();
	im= z.imag();
	}
	return *this;
}
Cplx& Cplx::operator+=(const Cplx& z){
	re += z.real();
	im += z.imag();
	return *this;
}
Cplx& Cplx::operator-=(const Cplx& z){
	re -= z.real();
	im -= z.imag();
	return *this;
}
Cplx& Cplx::operator*=(const Cplx& z){
	re= re*z.real() - im*z.imag();
	im= re*z.imag() + im*z.real();
	return *this;
}
Cplx& Cplx::operator/=(const Cplx& z){
	double t = z.real()*z.real()+z.imag()*z.imag();
	re= ( re*z.real() + im*z.imag()) /t;
	im= (im*z.real() - re*z.imag()) /t;
	return *this;
}
double Cplx::mod(const Cplx z) {
	double x = z.real();
	double y = z.imag();
	return sqrt(x*x+y*y);
}
double Cplx::arg(const Cplx z) {
    double x = z.real();
	double y = z.imag();
	return atan2(x, y);
}
istream& operator>>(istream& is, Cplx& z) {
double x, y;
is>>x>>y;
z.setreal(x);
z.setimag(y);
return is;

}

ostream& operator<<(ostream& os, const Cplx& z) {
	os<< "("<<z.real() <<","<<z.imag() <<")" <<endl;
	return os;
}
int operator == (const Cplx& s, const Cplx& d) {
	return s.real() == d.real() && s.imag() == d.imag();
}
int operator != (const Cplx& s, const Cplx& d) {
	return s.real() != d.real() || s.imag() != d.imag();
}
Cplx  operator +(const Cplx& s, const Cplx& d) {
	return Cplx(s.real()+d.real(), s.imag()+d.imag());
}

but here at the and of the code I receive an error
"cannot overload function distinguished by return type alone"
and I don't know how to get over it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.