#include
using namespace std;
template void swap(T &a,T &b){
T temp;
temp = a;
a = b;
b = temp;
}
int main(){
char s1[] = "Hello",s2[] = "hi";
swap(s1,s2);//为什么这样写不对
}
#include
using namespace std;
template void swap(T &a,T &b){
T temp;
temp = a;
a = b;
b = temp;
}
int main(){
char s1[] = "Hello",s2[] = "hi";
swap(s1,s2);//为什么这样写不对
}
因为char[6]和char[3]不能用你的模板T表示,它们也不是一个类型
#include<iostream>
using namespace std;
template <class T>
void swap(T &a,T &b){
T temp;
temp = a;
a = b;
b = temp;
}
int main(){
string s1 = "Hello", s2 = "hi";
swap(s1,s2);
cout << s1 << endl << s2;
}