Practice mode C++

What is the effect of marking a single-argument constructor explicit?

Correct answer B. It cannot be used for implicit conversions or copy-initialisation

Explanation

Without explicit, a constructor such as Buffer(int size) also acts as an implicit conversion, so Buffer b = 10; or passing 10 to a function expecting Buffer silently creates an object. explicit blocks these implicit conversions while still allowing direct initialisation like Buffer b(10). Marking single-argument constructors explicit prevents surprising conversions and bugs.

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.