why doesn't this work??

i have to write a generic function to sort int,float and char values and this isn't working.what is the mistake in the following code?



#include<iostream>
using namespace std;

template<class T>void sort()
{
int n;
T temp;
cout<<"enter no. of elements";
cin>>n;
T a[n];
cout<<"enter elements";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"sorted elements are:";
for(int i=0;i<n;i++)
{
for(int j=0;j<i;j++)
{
if(a[j]>a[i])
{
a[j]=temp;
a[j]=a[i];
a[i]=temp;
}
}
}
for(int i=0;i<n;i++)
{
cout<<a[i];
}
}
int main()
{
sort();
return 0;
}
1,1 Top
Topic archived. No new replies allowed.