这个模板调用为什么失败,书上讲的没看懂,该怎么解决
这个模板调用为什么失败,书上讲的没看懂
------解决方案--------------------
- C/C++ code
#include<iostream> using namespace std; #include<windows.h> #include<locale.h> template<typename T> T fref(const T&, const T&) { } void main() { setlocale (LC_ALL,"chs"); int a[10], b[42]; fref(a,b); }
------解决方案--------------------
- C/C++ code
int* fref(int*, int*) {}//如果是这样就可以
------解决方案--------------------
LZ注意哦,你用的是引用~
template<typename T>
T fref(const T&, const T&)
{
}
引用的话a[10], b[42];是两种不同的类型
用指针吧
template<typename T>
T fref(const T*, const T*)
{
}