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
solution.cpp
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 6
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.13
Constructor Delegation Practice
Swipe to show menu
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
solution.cpp
Everything was clear?
Thanks for your feedback!
Awesome!
Completion rate improved to 3.13SectionΒ 2. ChapterΒ 6
single