BleepingComputer.com: A short program with faulty

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

A short program with faulty convertion errors

#1 User is offline   smilewithme 

  • New Member
  • Pip
  • Find Topics
  • Group: Members
  • Posts: 11
  • Joined: 18-March 05

  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.
}

This post has been edited by smilewithme: 31 May 2005 - 08:03 PM


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users