Overloads let functions share a name, but sometimes their bodies would repeat exactly the same steps. A function template describes those steps with a type parameter. The compiler uses the description to form functions for the types you actually call it with.
#include <iostream>
template <typename T>
T doubled(T value) {
return value + value;
}
int main() {
std::cout << doubled(6) << '\n';
std::cout << doubled(1.25) << '\n';
}
template <typename T> introduces a placeholder type named T. In the first call, argument deduction makes T an int; in the second it becomes double. Each T in that particular function follows the same substitution. typename means that this parameter represents a type, not an ordinary value.
Templates do not make every operation legal for every type. The example requires addition and a result that can be returned as T. Your function requires comparison. If a type does not support the operations in the body, using that template with the type will not compile.
The editor's larger template already has its declaration and parameter types. Replace the temporary return a; with a decision that compares both arguments. Returning the first argument happens to work for some calls, so use the reversed-argument probes to check that your function selects by value, not position. Both parameters have type T, so this simple template expects matching argument types; mixing an integer and a decimal can prevent deduction of a single T.
The Console contains both integer and decimal calls. They belong to the same task because one comparison rule fixes both. Notice that returning a or b returns a value; the function is not lending a reference to one of its local parameters.
This separate twice template returns value + value as type T. Calling twice(3) deduces int; calling twice(2.5) deduces double. The branches represent compile-time instantiations, not a runtime decision.
Edit main.cpp; the supplied Console probes already call your code.
larger using a comparison so it returns the larger argument (either is fine when equal). The supplied calls must print Integer: 9 and Decimal: 2.5. Reversing the arguments must still select those same larger values; the equal-argument probe prints Equal: 4.Use Run to inspect the Console, then Submit to check your work.