title: Parameterized constructors of derived class in C++
body: <p>There are two classes. One is derived from a base class. Both of these classes have parameterized constructors.<br></p>
  <pre><code>#include&lt;string&gt;
  #include&lt;iomanip&gt;
  
  //declaring parent class
  class parent
  {
  protected:
      int a;
  public:
      parent(int x);
      void displayx();
  };
  
  //declaring child class
  class child:public parent
  {
  private:
      int b;
  public:
      child(int y);
      void displayy();
  };
  
  //defining constructors and methods of parent class
  parent::parent(int x)
  {
      parent::a=x;
      std::cout&lt;&lt;&quot;parent \n&quot;;
  
  }
  void parent::displayx()
  {
      std::cout&lt;&lt;parent::a&lt;&lt;&quot;\n&quot;;
  }
  
  //defining constructors and methods of child class
  child::child(int y):parent(y)
  {
      child::b=y;
      std::cout&lt;&lt;&quot;child \n&quot;;
  }
  
  void child::displayy()
  {
      std::cout&lt;&lt;child::b;
  }
  
  //main function
  int main()
  {
      child c1(10);// creating a child object
      //displaying values of int a and int b
      c1.displayx();
      c1.displayy();
      return 0;
  }
  
  
  
  
  
  </code></pre>
  <p>In the above code, the value 10 will be passed to both constructors when I create an object of the class child.I would like to know is there a way I can recode the above code where I can pass a different value
  to the base class constructor whenever I create a child object and pass a value to its constructor.
  For example:- I will create a child object and pass value 20 to its constructor but I want to pass value input by a user to the base class constructor so that int a and int b will have different values(I assume that the base class constructor is implicitly invoked whenever I create a child constructor)
  Thank you!!</p>