Is it possible to define the default value for variables of a template function in C++?
Something like below:
template T sum(T a, T b,
Yes you can define a default value.
template T constructThird() { return T(1); } template T test(T a, T b, T c = constructThird()) { return a + b + c; }
Unfortunately constructThird cannot take a and b as arguments.