Whats in this post?
- Background and Explanation of the code
To copy code: Click “View Source” on the right of this code snippet.
Background and Explanation of the code
In this program, the statement derv d( 10, 15 ); in the main ( ) first invokes the constructor with two parameters derv (int, int) of the derived class which in turn implicitly invokes the base’s no parameter constructor base ( ) which is then executed.Then the derived constructor is executed which initialize passed values to its data members.
Base’s no parameter constructor
Derive’s constructor with two parameters