我正在尝试根据我的需要调整在可变参数模板函数中避免使用struct的解决方案.但是,我无法理解G ++的行为.考虑以下功能:
template <typename T, unsigned Size>
int nextline(const typename std::array<T, Size> ar) {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后是电话
nextline(std::array<int, 2> { 1,0 });
Run Code Online (Sandbox Code Playgroud)
与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 …Run Code Online (Sandbox Code Playgroud)