Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

# A short program with faulty

No replies to this topic

### #1 smilewithme

smilewithme

• Members
• 11 posts
• OFFLINE
•
• Local time:11:09 PM

Posted 31 May 2005 - 08:02 PM

My program has errors,but I don't know what's wrong with it.My teacher told us it could complete the convertions,however,it didn't work.Why?
The essential codes are here:
class rational
{public:
rational():a(0),b(1){}
rational(double i):a(i),b(100){}
rational(int i,int j):a(i),b(j){}
void print(){cout<<a<<"/"<<b<<endl;}
operator double(){return(static_cast<double>(a)/;}
private:
double a,b;
};
int greater(int i,int j)
{return(i>j?i:j);}
double greater(double x,double y)
{return(x>y?x:y);}
rational greater(rational w,rational z)
{return(w>z?w:z);}
int main()
{int i=12;
double y=1.56;
rational w(10),z(7.5);
cout<<greater(w,z); //right
cout<<greater(w,y); //right
cout<<greater(y,w); //error:3 overloads have similar convertions.
cout<<greater(i,w); //error:3 overloads have similar convertions.
}

Edited by smilewithme, 31 May 2005 - 08:03 PM.