Total days between 2 dates C++
<p>I am trying to solve a problem that asks me to give the total days between two dates. </p>

<p>I have to take care of some issues between those two dates, such as leap years and the way of inputting the years by the users. (For example, if you input 1 and 17, the code will still give you the difference is 16 years (2017 - 2001 = 16). I am not supposed to change ANYTHING inside the <code>main()</code> function. </p>

<p>Here is my code.</p>

<pre><code> #include &lt;iostream&gt;
 #include &lt;cmath&gt;

 using namespace std;

 class date
 {
    private:
    int m;
    int d;
    int y;

    public:
    date(int, int, int);
    int countLeapYears(date&amp;);
    int getDifference(date&amp;);
    int operator-(date&amp;);    
  };

   int main()
   {
    int day, month, year;
    char c;

    cout &lt;&lt; "Enter a start date: " &lt;&lt; endl;
    cin &gt;&gt; month &gt;&gt; c &gt;&gt; day &gt;&gt; c &gt;&gt; year;

    date start = date(month, day, year);

    cout &lt;&lt; "Enter an end date: " &lt;&lt; endl;
    cin &gt;&gt; month &gt;&gt; c &gt;&gt; day &gt;&gt; c &gt;&gt; year;

    date end = date(month, day, year);
    int duration = end-start;

     cout &lt;&lt; "The number of days between those two dates are: " &lt;&lt;    
     duration &lt;&lt; endl;

     return 0;
   }


    date::date(int a, int b, int c)
    {
    m = a;
    d = b;
    y = c;
    }

    const int monthDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31,   
    30, 31};

   int date::countLeapYears(date&amp; d)
   {
      int years = d.y;
      if (d.m &lt;= 2)
      years--;
      return years / 4 - years / 100 + years / 400;
    }

   int date::getDifference(date&amp; other)
   {

      int n1 = other.y*365 + other.d;

      for (int i=0; i&lt;other.m - 1; i++)
     {
       n1 += monthDays[i];
       n1 += countLeapYears(other);
      }

      return n1;
      }

   int date::operator-(date&amp; d) {
      int difference = getDifference(d);
      return difference;
    }
</code></pre>

<p>When I ran this code, it said <code>invalid binary operation between "date" and "date"</code>. </p>

<p>Now, I assume that when I initialized <code>int duration = end - start</code>, I should have gotten a number. I guess what I am doing wrong here is I failed to convert the (end - start) date type into an integer. I thought my function getDifference already took care of that issue, but apparently it did not.</p>