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

Pyyhkäise näyttääksesi valikon

book
Constructor Delegation Practice

Tehtävä

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.

Ratkaisu

cpp

solution

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 6
Pahoittelemme, että jotain meni pieleen. Mitä tapahtui?

Kysy tekoälyä

expand
ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

book
Constructor Delegation Practice

Tehtävä

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.

Ratkaisu

cpp

solution

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 6
Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Pahoittelemme, että jotain meni pieleen. Mitä tapahtui?
some-alt