我正在尝试根据我的需要调整避免可变参数模板函数中的结构中提出的解决方案。但是,我无法理解 G++ 的行为。考虑以下函数:
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>’
但是,如果我更改unsigned Size
为unsigned long Size
or ,它匹配size_t
。我不确定这里发生了什么。Size
调用中的参数不是std::array<T, Size>
转换为 asize_t
吗?