title: C++17 initializing base class constructor using drived class constants as the paramers of the base class constructor
body: <p>Now before  i continue with the question i would like to state  i have read that that const values, references must be initialized in the initialization list of the constructor. However i still  need clarification in this case.</p>
  
  <p>Here is a realy simple inheritance example with code attached <a href="https://github.com/courteous/constrcutorChaining" rel="nofollow noreferrer">https://github.com/courteous/constrcutorChaining</a></p>
  
  <p>class F : E</p>
  
  <p>class E : D</p>
  
  <p>class D : C</p>
  
  <p>class C : B</p>
  
  <p>class B : A</p>
  
  <p>The  only spcecific part here is that base class "A"  inherits publicly from a template "enable_shared_from_this"</p>
  
  <p>Now the different behavior i observe is  i.e. when I create  a share pointer of "E"  then the  "parameterized D constructor called : 17" is being called</p>
  
  <pre><code>shared_ptr&lt;E&gt; eInstance = make_shared&lt;E&gt;();
  
  default A constructor called
  default B constructor called
  default C constructor called
  parameterized D constructor called : 5
  default E constructor called
  </code></pre>
  
  <p>however if i create a shared pointer of class F like that </p>
  
  <pre><code>shared_ptr&lt;F&gt; fInstance = make_shared&lt;F&gt;();
  
  default A constructor called
  default B constructor called
  default C constructor called
  default D constructor called
  default E constructor called
  default F constructor called
  </code></pre>
  
  <p>then the default E constructor is called  Why is that in this case.</p>
  
  <p>I have found other answers in Stackoverflow that refere to the problem of the copy constructor not beein implemented i.e. </p>
  
  <p><a href="https://stackoverflow.com/questions/10690285/default-constructor-called-instead-of-parametrized-constructor">Default constructor called instead of parametrized constructor</a></p>
  
  <p>but in this case no cloning or coping is beeing done i.e. a simple base constructor explicitelly called. </p>
  
  <p>The expected behavior here should be that the parameterized class D constructor should always be called, but that is not the case when I create a shared pointer of F. Can someone tell me why and what would be the right approach toforce class F to take the path 
   F-> "default constructor" E->"default constructor " ->"parameterized D constructor called : 17".</p>
  
  <p>The interesting classes in this case are F, E and D</p>
  
  <p>F.h</p>
  
  <pre><code>#ifndef _F_
  #define _F_
  
  #include "E.h"
  
  #include &lt;string&gt;
  #include &lt;memory&gt;
  
  namespace constructroTest
      {
  
      class F : public virtual E {
  
  
      public:
          static const uint16_t fixedLength;
  
          explicit F();
          virtual ~F();
  
  protected:
          shared_ptr&lt;F&gt; shared_from_this()
              {
              return dynamic_pointer_cast&lt;F&gt;(E::shared_from_this());
              }
          };
  
      }
  
  
  #endif  //#ifndef _F_
  </code></pre>
  
  <p>E.h</p>
  
  <pre><code>#ifndef _E_
  #define _E_
  
  #include "D.h"
  
  #include &lt;string&gt;
  #include &lt;memory&gt;
  
  namespace constructroTest
      {
  
      class E : public virtual D
          {
  
      public:
          static const uint16_t fixedLength;
  
          explicit E();
          virtual ~E();
  
  protected:
          shared_ptr&lt;E&gt; shared_from_this()
              {
              return dynamic_pointer_cast&lt;E&gt;(D::shared_from_this());
              }
          };
  
      }
  
  #endif  //#ifndef _E_
  </code></pre>
  
  <p>D.h</p>
  
  <pre><code>#ifndef _D_
  #define _D_
  
  #include "C.h"
  #include &lt;string&gt;
  #include &lt;memory&gt;
  
  
  namespace constructroTest
      {
  
      class D : public virtual C
          {
  
  
      public:
          static const uint16_t fixedLength;
  
  
          explicit D();
          virtual ~D();
  
  
          explicit D(uint16_t dArgument);
  
  
  protected:
          shared_ptr&lt;D&gt; shared_from_this()
              {
              return dynamic_pointer_cast&lt;D&gt;(C::shared_from_this());
              }
          };
  
      }
  
  
  #endif  //#ifndef _D_
  </code></pre>