The template generation does not pay attention to executable statements in the template definition. The if (n > 0)
does not prevent recursive template bootstapping for GetNRands<0>, GetNRands<-1>
and so on. It's pity that VC++ can't detect this "instantiate forever" recursion.
To break this recursion you may define this template specialization for n = 0:
template <>
struct GetNRands<0> {
static void fillVector( set<int>& v, int max ){}
};
It's a template generation analogue of sacramental if (n == 0) return 1;
in famous (and the same absurd) recursive factorial ;)