title: Why do anonymous objects sometimes require a default constructor?
body: <p>If I write the following program, it works as I expect:</p>
  
  <pre><code>struct Foo {
      Foo (std::string x) { std::cout &lt;&lt; x &lt;&lt; std::endl; }
  };
  
  int main () { Foo("hello, world"); }
  </code></pre>
  
  <p>However, if I write a slightly different program, I get a compilation error:</p>
  
  <pre><code>struct Foo {
      Foo (std::string x) { std::cout &lt;&lt; x &lt;&lt; std::endl; }
  };
  
  std::string x("hello, world");
  
  int main () { Foo(x); }
  </code></pre>
  
  <p>The error is:</p>
  
  <blockquote>
    <p><code>prog.cc: In function 'int main()':</code><br><code>prog.cc:10:20: error: no matching function for call to 'Foo::Foo()'</code></p>
  </blockquote>
  
  <p><a href="http://ideone.com/lWhOXH" rel="nofollow">The complete error can be seen on IDEONE.</a></p>
  
  <p><strong>Why does the error occur for the second program and not the first?</strong></p>