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
derv d (10, 20);
in main ( ) invokes the constructor with two parameters of derv class which passes the values 10 and 20 to the formal arguments bb and aa respectively.The constructor with two parameters
derv (int bb, int aa) : base (aa)
passes the argument aa to its base class single parameter constructor to initialize its data member a by explicitly invoking it.After its execution , the control returns back to the derive constructor with two parameters which then initialize its own data member b with value stored in bb.Finally the values are displayed.
Base’s single parameter constructor
Derived’s two parameter constructor
a = 20 b = 10