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

Swipe to show menu

book
Constructor Delegation Practice

Task

Swipe to start coding

You're working with a class that has multiple constructors. During code review, you were asked to refactor them using initialization lists for better performance and cleaner code.

  • The default constructor should delegate to the main constructor, passing default values.
  • The constructor that sets only the name should also delegate, using defaults for the other fields.
  • The one that sets name and age should delegate too, passing a default salary.
  • The fully parameterized constructor stays as is.

Solution

cpp

solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 6

Ask AI

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

book
Constructor Delegation Practice

Task

Swipe to start coding

You're working with a class that has multiple constructors. During code review, you were asked to refactor them using initialization lists for better performance and cleaner code.

  • The default constructor should delegate to the main constructor, passing default values.
  • The constructor that sets only the name should also delegate, using defaults for the other fields.
  • The one that sets name and age should delegate too, passing a default salary.
  • The fully parameterized constructor stays as is.

Solution

cpp

solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 6
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt