1、使用自动类型推导时,必须要推导出一致的数据类型
2、必须要确定T的类型,
#include<iostream>
using namespace std;
template<class T>
void myswap(T& a, T& b) {
T tmp = a;
a = b;
b = tmp;
}
template<class T>
void func() {
cout << "func函数调用" << endl;
}
void test() {
int a = 10;
int b = 20;
char c = 'c';
//myswap(a, c);//推出的类型不一致
func<int>();//必须要确定T的类型,才可以使用
}
int main() {
test();
return 0;
}
才可以使用