title: Overloading << with ostream and an enum type
body: <p>Following is my code. I am trying to print an enumerated data type variable, one directly which its name and another with a function with returns the same data type as the original variable.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  enum days{SUN, MON, TUE, WED, THU, FRI, SAT};
  
  
  inline days dayaftertomorrow(days d)
  {
    return static_cast&lt;days&gt;((static_cast&lt;int&gt;(d) + 2) % 7);
  }
  
  ostream&amp; operator&lt;&lt; (ostream&amp; out, days&amp; day)
  {
    switch(day)
    {
      case SUN: out &lt;&lt; "SUN"; break;
      case MON: out &lt;&lt; "MON"; break;
      case TUE: out &lt;&lt; "TUE"; break;
      case WED: out &lt;&lt; "WED"; break;
      case THU: out &lt;&lt; "THU"; break;
      case FRI: out &lt;&lt; "FRI"; break;
      case SAT: out &lt;&lt; "SAT"; break;
    }
    return out;
  }
  
  
  int main(int argc, char const *argv[]) {
    days d = MON, e;
    e = dayaftertomorrow(d);
    cout &lt;&lt; d &lt;&lt; "\t" &lt;&lt; e &lt;&lt; endl;
    cout &lt;&lt; d &lt;&lt; "\t" &lt;&lt; dayaftertomorrow(d) &lt;&lt; endl;
    return 0;
  }
  </code></pre>
  
  <p>I expect the result as </p>
  
  <pre><code>MON     WED
  MON     WED
  </code></pre>
  
  <p>But I am getting </p>
  
  <pre><code>MON     WED
  MON     3
  </code></pre>
  
  <p>How would I fix this?</p>