title: C++ temporary variables in initialization list
body: <p>In C++, is there any way to have something like a temporary variable in an initialization list. I want to initialize two constant members with the same instance of something without having to pass that something in, remove the const requirement, use a Factory (i.e. pass it in but have the factory generate it to hide it from the API user), or have temp actually be a member variable.</p>
  
  <p>I.e. something like </p>
  
  <pre><code>Class Baz{
      const Foo f;
      const Bar b;
      Baz(Paramaters p):temp(p),f(p,temp),b(p,temp){ //temp is an instance of Something
                                                    // But NOT A member of Baz
      // Whatever
      }
  }
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>Class Baz{
      Foo f;
      Bar b;
      Baz(Paramaters p){
          Something temp(p);
          f = Foo(p,temp)
          b = Bar(p,temp)
      }
  }
  </code></pre>
  
  <p>or </p>
  
  <pre><code>Class Baz{
      Foo f;
      Bar b;
      Baz(Paramaters p,Something s):f(p,s),b(p,s){
      }
  }
  </code></pre>