1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. What does the compiler do when it meets a call to a…

Added 30 Nov -0001

What does the compiler do when it meets a call to a function template?

  1. It converts the arguments to a common base class
  2. It generates a concrete function for the deduced types Correct answer
  3. It boxes the arguments and calls a generic wrapper
  4. It defers the call until the program is executed

Correct answer

B. It generates a concrete function for the deduced types

16 views

MCQSEXAM

Explanation

A function template is only a pattern: on seeing a call, the compiler deduces the template arguments from the argument types and instantiates a separate ordinary function for that combination. Each instantiation is compiled and type-checked like hand-written code, so a type that lacks a required operation fails at compile time rather than at run time. This is why templates give static polymorphism without the vtable cost of virtual functions.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? 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