I have an error :
with the code:error: ambiguous overload for ‘operator>>’ in ‘std::cin >> p’
That's everything in the file. Clearly I'm not trying to overload >>Code:#include "Time.h" #include <iostream> #include <sstream> #include <string> using namespace std; // Time::Time(){ // period=0; // seconds=0; // } Time::Time(const int p, const int m, const double s){ if (p<=2) { while((p<0||p>2) || (m<0 || m>=20) || (s<0 || s>=60)) { cout<<"REGULATION\nIncorrect time, please try again."<<endl<<"Period: "; cin >> p; cout<<endl<<"Minutes: "; cin >> m; cout << endl << "Seconds: "; cin>>s; cout<<endl; } } else if(p>=3) { while((p<3) || (m<0 || m>=5) || (s<0 || s>=60)) { cout<<"OVERTIME\nIncorrect time, please try again."<<endl<<"Period: "; cin>>p; cout<<endl<<"Minutes: "; cin>>m; cout<<endl<<"Seconds: "; cin>>s; cout<<endl; } } period=p; seconds=(double)(m*60)+s; } //Time::~Time(){ //deconstructor //} double Time::difference(const Time& other) const { //If in overtime int diffPeriod=period-other.period; double diffSeconds=seconds-other.seconds; double total=diffPeriod*15*60+diffSeconds; if (total>=0) { return total; } else { return -1*total; } } const string Time::toString(){ ostringstream a; int p,m; double s; p=period; m=(int)(seconds/60); s=(seconds-(m*60)); if (s<10) { a << p << "|" << m << ":0" << s; } else { a << p << "|" << m << ":" << s; } return a.str(); } bool Time::operator<(Time& other) { if (period<other.period) { return true; } if (period==other.period) { if (seconds<other.seconds) { return true; } } return false; } bool Time::operator==(Time& other) { if(period==other.period && seconds==other.seconds) { return true; } return false; } ostream& operator<<(ostream& out, Time& other) { return (out << other.toString()); }
Any help would be great.



LinkBack URL
About LinkBacks


