title: C++ constructor: Initialize local variable before initializer list
body: <p>How to store temporary state, needed for the initializer list, in the constructor (on the stack)?</p>
  <p>For example, implementing this constructor …</p>
  <pre><code>// configabstraction.h
  #include &lt;istream&gt;
  
  class ConfigAbstraction
  {
  public:
      ConfigAbstraction(std::istream&amp; input);
  
  private:
      int m_x;
      int m_y;
      int m_z;
  };
  </code></pre>
  <p>… using a stateful helper class like this?</p>
  <pre><code>// mysillyparserdontworry.h
  #include &lt;json/reader.h&gt; //jsoncpp
  
  class MySillyParserDontWorry
  {
  public:
      MySillyParserDontWorry(std::istream&amp; input) { input &gt;&gt; m_parseTree; }
      int intByName(const char* name) const { return m_parseTree[name].asInt(); }
  
  private:
      Json::Value m_parseTree;
  };
  </code></pre>
  <p>My attempt:</p>
  <pre><code>// configabstraction.cpp
  
  ConfigAbstraction::ConfigAbstraction(std::istream&amp; input)
      : local_parserState(input) // init local variable first: Not possible!
      , m_a(local_parserState.intByName(&quot;a&quot;))
      , m_b(local_parserState.intByName(&quot;b&quot;))
      , m_c(local_parserState.intByName(&quot;c&quot;))
  {
      MySillyParserDontWorry local_parserState; // ...because it is local
  }
  </code></pre>