How to pass an array size as a template with template type?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: My compiler behaves oddly when I try to pass a fixed-size array to a template function. The code looks as follows: #include <algorithm> #include <iostream> #include <iterator> template < typename TSize , TSize N > void f ( TSize (& array )[ N ]) { std :: copy ( array , array + N , std :: ostream_iterator < TSize >( std :: cout , " " )); std :: cout << std :: endl ; } int main () { int x [] = { 1 , 2 , 3 , 4 , 5 }; unsigned int y [] = { 1 , 2 , 3 , 4 , 5 }; f ( x ); f ( y ); //line 15 (see the error message) } It produces the