error: ambiguous overload for ‘operator>>’ in ‘std::cin >> p’

This is a discussion on error: ambiguous overload for ‘operator>>’ in ‘std::cin >> p’ within the C++ Programming forums, part of the General Programming Boards category; I have an error : error: ambiguous overload for ‘operator>>’ in ‘std::cin >> p’ with the code: Code: #include "Time.h" ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    44

    error: ambiguous overload for ‘operator>>’ in ‘std::cin >> p’

    I have an error :
    error: ambiguous overload for ‘operator>>’ in ‘std::cin >> p’
    with the code:

    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());
    }
    That's everything in the file. Clearly I'm not trying to overload >>
    Any help would be great.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If p is a const int, how do you intend to read into it?

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    44
    Thanks, been looking at this code for a while and just overlooked it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble with operator*=()
    By Lurker in forum C++ Programming
    Replies: 10
    Last Post: 10-26-2003, 02:03 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21