1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. Why can a function template not be partially specialised…

Added 30 Nov -0001

Why can a function template not be partially specialised in C++?

  1. Function templates are chosen by overload resolution, so partial ordering fills that role Correct answer
  2. Partial specialisation of function templates was removed by the C++11 standard revision
  3. A function template needs a class template wrapper before it can be specialised at all
  4. Partial specialisation is allowed, but only when every template parameter is a reference type

Correct answer

A. Function templates are chosen by overload resolution, so partial ordering fills that role

16 views

MCQSEXAM

Explanation

Partial specialisation exists only for class templates; for function templates the same effect is obtained by adding overloads that the compiler ranks through partial ordering of candidates. Class templates do allow partial specialisation, and a function can dispatch to a specialised class to emulate it. Overloading is usually clearer and avoids surprises when explicit specialisation meets overload resolution.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C++ and Object-Oriented Programming MCQs

Practise all C++ and Object-Oriented Programming MCQs

Similar MCQs