Loading…
december code / try / cpp
No account needed. Answer, see why, move on.
Problem
A header defines template <typename T> T twice(T x) { return x + x; }, and a program calls twice(3) and twice(2.5). What does the compiler generate from the template?
twice(T x)
twice(3)
twice(2.5)
One function that handles any type at run time
Two functions, twice<int> and twice<double>, one for each type it is used with
Nothing: templates are expanded as text, like macros
A version of twice for every type in the program
Nothing here is saved. Create a free account to keep your progress, take an assessment and get your readiness score.