Constructor Delegation Practice
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
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.13Awesome!
Completion rate improved to 3.13
Constructor Delegation Practice
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
Thanks for your feedback!
single
Awesome!
Completion rate improved to 3.13
Constructor Delegation Practice
Swipe to show menu
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
Thanks for your feedback!