首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求高手帮忙解决方案

2012-05-06 
求高手帮忙请问一下一下模版该怎么用??template class Tvoid swap(T a[j-1],T a[j]){int tmpa[j-1]a[j

求高手帮忙
请问一下一下模版该怎么用??
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;} 

热点排行