没有与指定类型匹配的函数模板实例
No instance of function template matches the specified type
我读过这可能是IntelliSense的问题,但我真的不知道这是真是假。当我编译代码时,我遇到了一个错误(标题),不知道如何修复它。我的书(Stephen Prata的《Sams C++Primer Plus》)没有解决我的问题。我写了一个非常相似的程序,但问题没有出现。
也许问题出在类型说明符上?它和模板的一样吗?真的很抱歉我的语言。。。
#include <iostream>
template <typename T>
T maxn(T tab[], int size);
template <> float maxn<float>(float, int); // Problem appears here...
int main()
{
std::cin.get();
return 0;
}
template <typename T>
T maxn(T tab[], int size)
{
T max = tab[0];
for (int i = 1; i < size; i++)
{
if (tab[i] > max) max = tab[i];
}
}
我很感激你的建议。谢谢
特殊化的第一个参数不正确。您给出了float
,但根据模板,它应该是一个浮点数组。
template <> float maxn<float>(float[], int);
// ^
// You need to indicate that the first parameter is an array.
请注意,您没有为专门化声明主体,因此如果您尝试使用它,链接将失败。(除非您在另一个编译单元中提供实现。)
相关文章:
- 函数模板实例化、替换和重载解析的顺序是什么?
- 请参阅在 Visual Studio 2019 中捕获 std::exception 时对函数模板实例化消息的引用
- 函数模板实例化的 sfinae
- 如何简洁地编写大量显式函数模板实例化?
- 无法编译包含"if constexpr"的函数模板实例化
- CUDA 模板错误:没有与参数列表匹配的函数模板实例
- 合格的朋友函数模板实例化
- 没有与参数列表匹配"std::make_pair"函数模板实例
- 没有函数模板实例remove_if与参数列表匹配
- C++ 没有与指定类型匹配的函数模板实例
- 函数模板实例化失败
- 使用不完整类型的函数模板实例化
- C++ 具有隐式参数的函数模板实例化
- 定义指向函数模板实例的std::函数指针时出错,该实例是模板化类的成员
- 声明不带模板的函数模板实例化
- 没有与指定类型匹配的函数模板实例
- 类和函数模板实例化的Visual Studio dll导出问题
- 关于函数模板实例化的c++规则
- C++错误:"没有与所需类型匹配的函数模板实例"
- 在多个翻译单元中函数模板实例化的标识