operator overloading errors
Im trying to over load the / + * - operators, but cannot find a descent tutorial on doing so. Yes I've read up on overloading, and it is probably not a good idea till I know exactly what i'm doing, but I have to learn sometime. I'm not sure on who to use the functions in the program after I have written the implementation. How does the ostream work after overloading it? The same as before, or is there a new way of setting it up? Is what I have for the main so far correct?
Code:
#include <iostream>
#include <cstdlib>
bool division = false;
bool subtract = false;
bool add = false;
bool mult = false;
using namespace std;
class COMPLEX;
ostream operator<<(ostream&,const COMPLEX&);
istream operator>>(istream&, COMPLEX&);
class COMPLEX{
private:
int real, imaginary; //initial values
int realfin,imfin;
public:
COMPLEX(); //defines default constructor
~COMPLEX(); //destructor
COMPLEX operator/(COMPLEX&);
COMPLEX operator+(COMPLEX&);
COMPLEX operator*(COMPLEX&);
COMPLEX operator-(COMPLEX&);
friend ostream operator>>(istream&,const COMPLEX&);
friend istream operator>>(istream&, COMPLEX&);
}comp1,comp2,final; //define the classes to be used
// This is the main .cpp file, the other implementations are above this
istream operator>>(istream &strm, COMPLEX &obj){
cout<<"enter a real and imaginary number\n";
strm>> real >> imaginary;
cout<<"enter a second real and imaginary number\n";
strm>> obj.real >> obj.imaginary;
return strm;
}
int main(){
int real, imag;
cin>>comp1;
final = comp1 * comp2;
cout<<final;
final = comp1 / comp2;
cout<<final;
final = comp1 + comp2;
cout<<final;
final = comp1 - comp2;
}