Link to home
Start Free TrialLog in
Avatar of triggah
triggah

asked on

HELP WITH: error C2593: 'operator >>' is ambiguous???

Hi i need a little help with some code... i get the
error C2593: 'operator >>' is ambiguous 4 times (marked with a (*)
message when i try to compile this code

#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;


class Impedance
{
private:

float X, R;
     
public:

Impedance()
{
     X=0;
     R=0;
}

Impedance(float Rin, float Xin)
{
     if (R!=0)
     {
          R=Rin;
          X=Xin;
     }
     else
     {
     cout<<"R cannot be 0, please try again.\n";
     }
}

//Get's
float getR(){return(R);}
float getX(){return(X);}

//Set's
void setR(float r){R=r;}
void setX(float x){X=x;}

Impedance operator||(Impedance Zin)
{
     Impedance temp;
     temp.R=(R*Zin.getR())-(X*Zin.getX());
     temp.X=(R*Zin.getX())+(Zin.getR()*X);
     return(temp);
     
}

Impedance operator+(Impedance Zin)
{
     Impedance temp;
     temp.R=R+Zin.getR();
     temp.X=X+Zin.getX();
     return(temp);
     
}
friend istream& operator>>(istream &istr, Impedance &obj);
friend ostream& operator<<(ostream &ostr, Impedance &obj);

};

istream &operator>>(istream &istr, Impedance & obj)
{
float temp;
cout<<"Please enter the active resistance:  ";
istr>>temp;
obj.setR(temp);
cout<<"Please enter the reactive resistance:  ";
istr>>temp;
obj.setX(temp);
return(istr);
}

ostream &operator<<(ostream &ostr, Impedance & obj)
{
ostr<<obj.getR()<<"+i*"<<obj.getX();
return(ostr);
}


void main()
{
int choice=0,i=0;
Impedance Z1, Z2, Z3, Ztp, Zts;
while(choice!=2)
{
cout<<"Please select one of the following menu options:\n\t1)\tCalculate series and parallel impedance.\n\t2)\tExit\nSelection:  ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Please enter the impedance values for Z1:\n"<<setiosflags(ios::fixed)<<setprecision(2);
cin>>Z1; (*)
cout<<"Please enter the impedance values for Z2:\n";
cin>>Z2; (*)
cout<<"Please enter the impedance values for Z3:\n";
cin>>Z3; (*)
Ztp=Z1||Z2||Z3;
Zts=Z1+Z2+Z3;
cout<<"The parallel impedance is: "<<Ztp<<", and the series impedance is: "<<Zts<<".\n"; (*)
     
break;

case 2:
cout<<"Exiting program.\nThank you for choosing this program.\n";

break;

default:
cout<<"Please select a valid menu option!\n";

break;
}
}
}

If anyone can help me PLEASE do!!!

thanks
dan
Avatar of alexo
alexo
Flag of Antarctica image

Compiled without a hitch on MSVC++ 6.0 SP5
ASKER CERTIFIED SOLUTION
Avatar of alexo
alexo
Flag of Antarctica image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Recommendation: Accept comment from alexo

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

DominicCronin
EE Cleanup Volunteer