how do I write an overloaded >operator for istream that
let's say fraction class through set() can take several types:
void set(char*)
void set(long int num, long int den)
void set(double)
and that char* can handle hex strings, binary, and whatever C formatted
numbers you can throw at it, as long as it's a string.
how do I code this?
is could provide me with any number of types, and I don't know how to
detect them so I can call the proper set method.
my best guess is it's something along the lines of...
friend istream& operator>>(istream& is, fraction& f) {
switch(is.type???) {
case int:
char c;
long int num,den;
is>>num>>c>>den;
f.set(num, den);
break;
case double:
double d;
is>>d;
f.set(d);
break;
case string:
string s;
is >s;
f.set(s); //string automatically converts to char*
break;
default:
std::cerr<<"bad input\n";
break;
}
return is;
}
------------------------------------
Jim Michaels
for email, edit the address
RAM Disk is *not* an installation method.