This question is about functions that accept arrays of statically known size.
Take, for example, the following minimum program:
What at startup prints the expected result:
2 3 4 5 6 3 4 5 6 7
However, when I tried to get my compiler (VS 2010) to could not deduce template argument for 'int [n]' from 'int [5]' 5 , it could not deduce template argument for 'int [n]' from 'int [5]' .
Several studies led to the updated arrfun_b , where the deduction of the template parameter works:
template<size_t n> void arrfun_b(int (&a)[n]) { for(size_t i = 0; i < n; ++i) std::cout << ++(a[i]) << std::endl; }
The result of the program is the same whether arrfun_a or arrfun_b .
So far, the only difference I've found is whether the output of the template argument works, and if you can call a function with N that is not 5 ...
c ++ arrays
gha.st
source share