title: Overloading operators with structures in c++
body: <p>So I am doing a simple, (or so I thought) exercise to help build my C++ skills.</p>
  <p>I have this simple struct to keep track of date information. I need to overload an operator to display the results. This is a simple function that I have used before in classes, and never had any problems with. However, in this exercise I am getting the following error:</p>
  <p>Expression preceding parentheses of apparent call must have (pointer-to-) function type</p>
  <p>Here is my code. The problem function is the <code>ostream&amp; operator &lt;&lt; (ostream&amp; os, const Date date)</code> function and is commented in the code.</p>
  <pre><code>    #include&lt;iostream&gt;
      #include&lt;ostream&gt;
      #include &quot;error.h&quot;
  
      using namespace std;
  
      inline void keep_window_open(string s)
      {
          if (s == &quot;&quot;) return;
          cin.clear();
          cin.ignore(120, '\n');
          for (;;) {
              cout &lt;&lt; &quot;Please enter &quot; &lt;&lt; s &lt;&lt; &quot; to exit\n&quot;;
              string ss;
              while (cin &gt;&gt; ss &amp;&amp; ss != s)
                  cout &lt;&lt; &quot;Please enter &quot; &lt;&lt; s &lt;&lt; &quot; to exit\n&quot;;
              return;
          }
      }
          struct Date {   
              int year;
              int month;
              int day;
          };
          Date today;
          Date tomorrow;
  
          // Helper functions
          void initializeDay(Date&amp; date, int year, int month, int day)
          {
              if (month &lt; 1 || month &gt; 12)
              {
                  error(&quot;Invalid month&quot;);
              }
              if (day &lt; 1 || day &gt; 31)
              {
                  error(&quot;Invalid day&quot;);
              }
              date.year = year;
              date.month = month;
              date.day = day;
          }
  
          void addDay(Date&amp; date, int daysToAdd)
          {
              date.day += daysToAdd;
          }       
  
          // Does not work    
          ostream&amp; operator &lt;&lt; (ostream&amp; os, const Date date)
          {
              return os &lt;&lt; '(' &lt;&lt; date.year()
                  &lt;&lt; ',' &lt;&lt; date.month()
                  &lt;&lt; ',' &lt;&lt; date.day()
                  &lt;&lt; ')';
          }
  
      int main()
      {           
          initializeDay(today, 2020, 9, 21);  
          tomorrow = today;
          addDay(tomorrow, 1);
  
          keep_window_open(&quot;~&quot;);
  
          return 0;
      }
  </code></pre>
  <p>Like I said I have used the problem function before without problem. The only thing I can think of is it is has something to do with the struct, but that doesn't make sense to me. So I am thinking it maybe something else.</p>
  <p>Any help would be greatly appreciated. Thank you for your time and your help.</p>