title: unexpected behavior of overloaded operator "<<" c++
body: <p>I wrote a simple program to demonstrate the use of overloaded operator &lt;&lt; in c++. According to this article: <a href="https://docs.microsoft.com/en-us/cpp/standard-library/overloading-the-output-operator-for-your-own-classes?view=msvc-160" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/cpp/standard-library/overloading-the-output-operator-for-your-own-classes?view=msvc-160</a>, I tried writing my own code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  class Date
  {
  private:
      std::string str;
  public:
      Date(int x) : str(5, 'x'){}
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Date&amp; dt){
          os &lt;&lt; dt.str;
          return os;
      }
  };
  
  int main()
  {
      Date dt(6);
      std::cout &lt;&lt; dt;
  }
  </code></pre>
  <p>This code worked correctly as it printed &quot;xxxxx&quot; to the console. However when I remove the argument of the constructor:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  class Date
  {
  private:
      std::string str;
  public:
      Date() : str(5, 'x'){}
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Date&amp; dt){
          os &lt;&lt; dt.str;
          return os;
      }
  };
  
  
  int main()
  {
      Date dt();
      std::cout &lt;&lt; dt;
  }
  </code></pre>
  <p>, I got &quot;1&quot; printed to the console. I have no idea why this happens.</p>