title: Initialization of data members of a class in c++
body: <p>For a class in c++,we can provide a default constructor as well as any no of parameterized constructors.If we use a constructor initializer list in each of parameterized constructor,then isnt it like we are <strong>initializing</strong> a member more than one time?Is the concept valid?(I thought we can initialize only once).
  Also by this logic,if we have a constant data member or a reference,and if I want to initialize the constant with a value provided by user,how can I do it?I found a code snippet in c++ primer which looks like</p>
  
  <pre><code>  class constref
     {
      public:
          constref(int ii):i(ii),ci(ii),ri(i)
          {
          }
      private:
          int i;
          const int ci;
          int &amp;ri;
  }
  </code></pre>
  
  <p>Isnt the above code wrong.because since we have provided a constructor with parameters,we need to define a default constructor.So the constant and the reference are initialized two times which is an error.How can I make it work?
  Thanks</p>
  
  <p>But can you please tell what is happening in this code?</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;stdlib.h&gt;
  using namespace std;
  
  class dummy
  {
      int a;
  public:
        dummy():a(0)
        {
        }
        dummy(int i):a(i)
        {
        }
        void output()
        {
          cout&lt;&lt;a&lt;&lt;endl;
        }
     };
     int main()
     {
      dummy d;
      d=dummy(4);
      d=dummy(3);
      d.output();
      return 0;
    }
  </code></pre>