title: c++ passing a string literal instead of a const std::string&?
body: <p>I have the following code which compiles with no warnings (-Wall -pedantic) with g++</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  class Foo
  {
  public:
      Foo(const std::string&amp; s) : str(s)
      { }
  
      void print()
      {
          cout &lt;&lt; str &lt;&lt; endl;
      }
  
  private:
      const std::string&amp; str;
  };
  
  
  class Bar
  {
  public:
  
      void stuff()
      {
          Foo o("werd");
          o.print();
      }
  };
  
  
  int main(int argc, char **argv)
  {
      Bar b;
      b.stuff();
  
      return 0;
  }
  </code></pre>
  
  <p>But when I run it, only the newline is printed out. <em>What is going on?</em></p>
  
  <p>If I were to do this inside stuff:</p>
  
  <pre><code>string temp("snoop");
  Foo f(temp);
  f.print();
  </code></pre>
  
  <p>then it works fine!</p>