Hello,
i am posting the code. Please tell me why is one of the function defintion working and one is not??even though they both look identical!
i have written the comments also like which one is working and which one is not. Please have a look at them and give me the reason!
Code:
#include <iostream.h>
#include <string.h>
class student
{
char *name,roll[3];
public:
student()
{
name=new char[20];
}
student(char *n,char *r)
{
strcpy(name,n);
strcpy(roll,r);
}
friend void sort(student []); //Why This Doesn't Work?
friend void sort(student *); //This Works Perfectly??..
};
void sort(student a[]) //Why Not Working??
{
int j;
student temp;
for(int i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
if(strcmp(a[j].roll,a[j+1].roll)>0)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
int main(void)
{
student a[3];
a[0]=student("abc","1");
a[1]=student("def","2");
a[2]=student("hij","3");
sort(a);
return 0;
}