Avoiding struct in variadic template function에 제시된 솔루션을 필자의 필요에 맞게 적용하려고합니다. 그러나 G ++의 동작을 이해할 수는 없습니다. 내가 unsigned long Size
또는 size_t
에 unsigned Size
를 변경하는 경우가 일치하지만non size_t 정수가있는 std :: array에 대한 C++ 템플릿 매개 변수 공제
template <typename T, unsigned Size>
int nextline(const typename std::array<T, Size> ar) {
return 0;
}
그런 다음 호출
nextline(std::array<int, 2> { 1,0 });
는 GCC와 일치하지 않는
eslong.cpp: In function ‘int main()’:
eslong.cpp:10:38: error: no matching function for call to ‘nextline(std::array<int, 2ul>)’
nextline(std::array<int, 2> { 1,0 });
^
eslong.cpp:10:38: note: candidate is:
eslong.cpp:4:5: note: template<class T, unsigned int Size> int nextline(std::array<T, Size>)
int nextline(const typename std::array<T, Size> ar) {
^
eslong.cpp:4:5: note: template argument deduction/substitution failed:
eslong.cpp:10:38: note: mismatched types ‘unsigned int’ and ‘#‘integer_cst’ not supported by dump_type#<type error>’
nextline(std::array<int, 2> { 1,0 });
^
eslong.cpp:10:38: note: ‘std::array<int, 2ul>’ is not derived from ‘std::array<T, Size>’
과 불평 : 다음 함수를 고려하십시오. 나는 여기서 무슨 일이 일어나고 있는지 이해할 수 없다. std::array<T, Size>
에 대한 호출의 Size
매개 변수가 size_t
으로 변환되지 않았습니까?
그것은 나를 위해 잘 컴파일 : http://ideone.com/1FEmgZ – yizzlez
1)'typename' 여기 ('const typename std :: array ....')에 잘못되었습니다. 2) 비 형식 템플릿 매개 변수의 유형과 정확히 일치해야합니다. [temp.deduct.type]/17을 참조하십시오. – dyp