Может ли кто-нибудь объяснить разницу между двумя вызовами функций здесь?
Когда вы можете передать шаблонную переменную в функцию?
В обоих случаях я должен получить шаблонный массив внутри функция, но компилируется только одна.
template<int DIM>
struct MyStruct
{
array<int, DIM> structArr;
};
template<int DIM> void testA( MyStruct <DIM>& myStruct) { }
template<int DIM> void testB( array<int, DIM>& arrA) { }
int main()
{
MyStruct<3> myStruct;
array<int, 3> arr;
testA(myStruct);
testB(arr); //compile error
return 0;
}
РЕДАКТИРОВАТЬ: сообщения об ошибках выглядят следующим образом:
error: no matching function for call to ‘testB(std::array&)’
testB(arr); //compile error
^
note: candidate: template void testB(std::array&)
template<int DIM> void testB( array<int, DIM>& arrA) { }
^~~~~
note: template argument deduction/substitution failed:
note: mismatched types ‘int’ and ‘long unsigned int’