What does the compiler do when it meets a call to a function template?
Correct answer
B. It generates a concrete function for the deduced types
16 views
B. It generates a concrete function for the deduced types
16 views
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.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is B? Ask here and get an explanation.