Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Constructor Delegation Practice | Constructors and Destructors
C++ OOP

Constructor Delegation PracticeConstructor Delegation Practice

Task

  • Rewrite this constructors using constructor delegation.

    • The default constructor should delegate to a parameterized constructor, passing default values.
    • The constructor that initializes only the name should delegate to the parameterized constructor, passing default values for the other members.
    • The constructor that initializes name and age should delegate to the parameterized constructor, providing a default value only for salary.
    • The constructor that initializes all member variables remains unchanged.

Everything was clear?

Section 2. Chapter 6
toggle bottom row

Constructor Delegation PracticeConstructor Delegation Practice

Task

  • Rewrite this constructors using constructor delegation.

    • The default constructor should delegate to a parameterized constructor, passing default values.
    • The constructor that initializes only the name should delegate to the parameterized constructor, passing default values for the other members.
    • The constructor that initializes name and age should delegate to the parameterized constructor, providing a default value only for salary.
    • The constructor that initializes all member variables remains unchanged.

Everything was clear?

Section 2. Chapter 6
toggle bottom row
some-alt