求高手帮忙
请问一下一下模版该怎么用??
template <class T>
void swap(T a[j-1],T a[j])
{
int tmp=a[j-1];
a[j-1]=a[j];
a[j]=tmp;
}
这样为什么不行?
[解决办法]
- C/C++ code
template <class T>void my_swap(T& a,T& b){ T tmp=a; a=b; b=tmp;}int main(){ int i=1,j=20; my_swap(i,j); cout<<i<<" "<<j<<endl; return 0;}