Practice mode C++

Given template <typename T> T mx(T a, T b), what happens with the call mx(3, 2.5)?

Correct answer D. Compilation fails because T is deduced as both int and double

Explanation

Template argument deduction is done separately for each function argument, and the results must agree. Here the first argument deduces T = int and the second T = double, so deduction fails and no implicit conversion is attempted. You can fix it with an explicit argument, mx(3, 2.5), or by casting one argument so both types match.

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.