title: Base class as argument in derived class constructor in c++
body: <p>I'm having trouble with constructors in derived classes. Lets say I have the simple code below here with one base class Base and two classes whom inherits from Base, Derived1 and Derived2.  </p>
  
  <p>I want Derived2 to hold a pointer to Base, which could point either to Base or Derived1. I cannot manage to write the constructor for this tho. If I pass in a Derived1 object I get a empty Base once inside the constructor. </p>
  
  <pre><code>Class Base
  {
  public:
        Base(int a): m_a(a)
        {
        }
  
  protected:
           int m_a;
  };
  
  
  //First derived class of base
  class Derived1 : public Base
  {
  public:
          Derived1(double c): m_c(c)
          {
          }
  
  private:
          double m_c;
  };
  
  
  //Second derived class of Base
  class Derived2 : public Base
  {
  public:
          Derived2(Base b, int k): m_b(&amp;b), m_k(k)
          {
          }
  
  private:
          int m_k;
          Base* m_b;
  };
  
  
  int main()
  {
      Base b(2);
      Derived1 d1(3.0);
  
  
      Derived2 d2(d1, 3);
      Derived2 d3(b, 4);
  }
  </code></pre>