Note that the function is defined below the function call.
You have two possible approaches:
Approach 1:
#include <iostream> #include <type_traits> using namespace std; template <size_t N> typename enable_if<N == 1, void> ::type f() { cout << 1; } template <size_t N> typename enable_if<(N > 1), void>::type f(){ cout << N - 1 << ' '; f<N - 1>(); } int main() { f<4>(); }
Approach 2:
You can forward declare prototype for function version N==1 .
Tryinhard
source share