Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
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.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

A short program with faulty


  • Please log in to reply
No replies to this topic

#1 smilewithme

smilewithme

  • Members
  • 11 posts
  • OFFLINE
  •  
  • Local time:07:02 PM

Posted 31 May 2005 - 08:02 PM

:thumbsup: 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)/:flowers:;}
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.


BC AdBot (Login to Remove)

 


m



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users