Practice mode C++

Which class members MUST be initialised in a constructor’s member initialiser list (or with a default member initialiser) rather than assigned in the constructor body?

Correct answer A. const data members and reference members

Explanation

By the time the constructor body runs, every member has already been initialised. A const member cannot be assigned afterwards and a reference cannot be reseated, so both must be given their values in the initialiser list or by a default member initialiser. Members of class types without a default constructor have the same requirement. Static members are defined outside the constructor altogether.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.