title: Pro/con: Initializing a variable in a conditional statement
body: <p>In C++ you can initialize a variable in an if statement, like so:</p>
  
  <pre><code>if (CThing* pThing = GetThing())
  {
  }
  </code></pre>
  
  <p>Why would one consider this bad or good style? What are the benefits and disadvantages?</p>
  
  <p>Personally i like this style because it limits the scope of the pThing variable, so it can never be used accidentally when it is NULL. However, i don't like that you can't do this:</p>
  
  <pre><code>if (CThing* pThing = GetThing() &amp;&amp; pThing-&gt;IsReallySomeThing())
  {
  }
  </code></pre>
  
  <p>If there's a way to make the above work, please post. But if that's just not possible, i'd still like to know why.</p>
  
  <p><a href="https://stackoverflow.com/questions/136373/initializing-a-variable-in-a-conditional-statment">Question borrowed from here, similar topic but PHP.</a></p>