On 05/08/2015 08:05 AM, Dennis Ritchie wrote: > why static int idx variable declared within a > function deepDup takes the values 1, 1, 1, 2, 2, 3, 4, as opposed to a > global variable static int idx, which receives the expected value of 1, > 2, 3, 4, 5, 6, 7 ?
That's because every template instance is a different type (or implementation). Just like the static variables of foo and bar are separate below, so are the static variables of t!int and t!float:
void foo() { static int i; } void bar() { static int i; } void t(T)() { static int i; } Ali