title: (C++) error: use of overloaded operator '<<' is ambiguous (with operand types 'ostream' (aka 'basic_ostream<char>')
body: <p>I overloaded the Extraction and Insertion operators. But now whenever they're being called in main.cpp the compiler tells me that there's an ambuiguity error. I sorta understand what ambiguity errors are, but I can't for the life of me figure out why it's happening.</p>
  
  <p>I'm using g++ compiler and LLDB debugger if it helps.</p>
  
  <p>The Error:</p>
  
  <pre><code>/Users/Final Project/ms1.cpp:147:12: error: use of overloaded operator '&lt;&lt;' is ambiguous (with operand types 'ostream' (aka 'basic_ostream&lt;char&gt;') and 'oop244::Date')
        cout &lt;&lt; A &lt;&lt; " is not equal to " &lt;&lt; B &lt;&lt; " but operator!= returns otherwise!" &lt;&lt; endl;
        ~~~~ ^  ~
  /Users/Final Project/Date.h:57:17: note: candidate function
    std::ostream&amp; operator&lt;&lt;(std::ostream os, Date&amp; Dob);
  </code></pre>
  
  <p>Followed by a billion other similar errors.</p>
  
  <p>My main (where the error occurs):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #include "Date.h"
  #include "Date.cpp"
  #include "general.h"
  using namespace std;
  using namespace oop244;
  bool equalDates(const char* A, const char* B);
  int main(){
    int ret = 0;
    char confirm[2000];
    bool ok = true;
    Date A(2018, 10, 18);
    Date B;
  ......
  ......
  A = Date(2018, 10, 17);
    if (ok){
      cout &lt;&lt; "testing operator!=" &lt;&lt; endl;
      if (A != B){
        cout &lt;&lt; "passed!" &lt;&lt; endl;
      }
      else{
        cout &lt;&lt; A &lt;&lt; " is not equal to " &lt;&lt; B &lt;&lt; " but operator!= returns otherwise!" &lt;&lt; endl;
        ok = false;
      }
    }
  </code></pre>
  
  <p>Class declaration</p>
  
  <pre><code>#ifndef __244_DATE_H__
  #define __244_DATE_H__
  // header file includes
  #include "general.h"
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  
  namespace oop244{
  
    class Date{
    private:
      // private member variables
      int _year;
      int _mon;
      int _day;
      int _readErrorCode;
  
      // private member functions and setters
      int value()const;
      void setErrCode(int errCode);
  .....
  .....
  
    public:
      // constructors
      Date();
      Date(int,int,int);
      ~Date();
  
      std::ostream&amp; write(std::ostream&amp; ostr, Date&amp; dob);
      std::istream&amp; read(std::istream&amp; istr, Date&amp; dob);
  
    };
  
    std::istream&amp; operator&gt;&gt;(std::istream is, Date&amp; dob);
    std::ostream&amp; operator&lt;&lt;(std::ostream os, Date&amp; dob);
  
      }
  #endif
  </code></pre>
  
  <p>Class function definitions</p>
  
  <pre><code>#include "general.h"
  #include "Date.h"
  #include &lt;iomanip&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  namespace oop244{
  
    // constructors
    Date::Date()
    {
      _year=0;
      _mon=0;
      _day=0;
      _readErrorCode=NO_ERROR;
    }
  
    Date::Date(int year,int month, int day)
    {
      _year=year;
      _mon=month;
      _day=day;
      _readErrorCode=NO_ERROR;
    }
  
    Date::~Date() {}
  
    // member functions
  
    void Date::setErrCode(int errCode)
    {
      _readErrorCode=errCode;
    }
  
    void Date::passErr(int errCode)
    {
      setErrCode(errCode);
    }
  .....
  .....
    int Date::getErrCode() const
    {
      return _readErrorCode;
    }
  
  
    std::istream&amp; Date::read(std::istream&amp; istr, Date&amp; dob) 
    {
      char y[5],m[3],d[3];
      int year,month,day;
  
      istr.getline(y,5,'/');
      istr.getline(m,3,'/');
      istr.getline(d,3,'/');
  
      year=atoi(y);
      month=atoi(m);
      day=atoi(d);
  
      Date temp (year,month,day);
  
      if (year&gt;=2000 &amp;&amp; year&lt;=2030)
        dob.passErr(YEAR_ERROR);
      else if (month+=1 &amp;&amp; month&lt;=12)
        dob.passErr(MON_ERROR);
      else if (day&gt;=1 &amp;&amp; day&lt;=31)
        dob.passErr(DAY_ERROR);
      else
      {
        dob.passErr(NO_ERROR);
        dob=temp;
      }
      return istr;
    }
  
    std::ostream&amp; Date::write(std::ostream&amp; ostr, Date&amp; dob)
    {
      int year=dob.getYear();
      int month=dob.getMonth();
      int day=dob.getDay();
      ostr&lt;&lt;year&lt;&lt;"/"&lt;&lt;month&lt;&lt;"/"&lt;&lt;day&lt;&lt;endl;
      return ostr;
    }
  
    // non-memeber operator overloads
  std::istream&amp; operator&gt;&gt;(std::istream&amp; is, Date&amp; dob)
  {
    dob.read(is,dob);
    return is;
  }
  
  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, Date&amp; dob)
  {
    dob.write(os,dob);
    return os;
  }
  
  }
  </code></pre>
  
  <p>Sorry for the super long post. I'm kinda at the end of my wits. My thank to you guys in advance.</p>