关于模板函数和模板类的问题
我用template写了一个排序的函数,又写了一个类,想用这个函数对类里的成员排序,可是怎么也不成。请教下应该怎么改?谢谢
template<class T>
void bubble(T a[],int l, int r) //bubble sort
{
int i,j;
for(i=l;i<r;i++)
for(j = r; j > i; j--)
if(a[j-1]<a[j])
{
T temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
}
template<class T>
class Bag
{
T m_a[10];
int m_size;
public:
......
};
void main()
{
int i;
int data[5];
for (i=0; i<5; i++)
{
cout << "\nEnter data element: ";
cin >> data[i];
}
bubble(data,0,10);// it works
for (i=0; i<5; i++)
{cout << data[i] << " ";}
cout << endl;
Bag<int> temp1;
bubble(temp1, 0, 10); //bubble doesn't work with the Bag class, how to fix it?
}