0

Base Class and Derived Class Constructor Arguments

Peace be upon those who follow the guidance, Let’s suppose I have a base class that has a constructor which takes parameters. So instantiating an object from this class requires passing arguments. Suppose I have a derived class which inherits from the base class, and this derived class also takes parameters in its constructor. So, how do I pass arguments to both constructors? Please forgive me if this is a trivial question.

11th Mar 2021, 5:56 AM
Alexander Kramnik
Alexander Kramnik - avatar
1 Answer
+ 3
Just call the base constructor inside the derived constructor's initializer list like: Derived( int param1, double param2 ) : Base( param1, param2 ) {}
11th Mar 2021, 9:15 AM
Dennis
Dennis - avatar