+ 3
[C++] why it doesn't increment if argument is a float?
Result is "223": template<class T> void f(T){ static int i = 1; cout << ++i; } int main(){ f(1); f(1.0); f(1); }
1 Respuesta
+ 5
Because template expansion is done during compile time and not at runtime.
So at runtime there exist 2 seperate functions "f ()" ( one for float and one for int ) and f(1.0) is calling different function than f(1)