title: C++: Initialization of member variables
body: <p>I have a confusion on class member variable initialization.</p>
  
  <p>Suppose in my .h file is:</p>
  
  <pre><code>class Test {
  
  int int_var_1;
  float float_var_2;
  
  public:
         Test();
  }
  </code></pre>
  
  <p>My .cpp would be:</p>
  
  <pre><code>Test::Test() : int_var_1(100), float_var_2(1.5f) {}
  </code></pre>
  
  <p>Now when I instantiate a class the variables get initialized to 100 and 1.5.</p>
  
  <p>But if that is all I'm doing in my constructor, I can do the following in my .cpp:</p>
  
  <pre><code>int Test::int_var_1 = 100;
  float Test::float_var_2 = 1.5f;
  </code></pre>
  
  <p>I'm confused as to the difference between initializing the variables in constructors or with the resolution operator.</p>
  
  <p>Does this way of initializing variables outside constructor with scope resolution only apply to static variables or is there a way it can be done for normal variables too?</p>