关于重载<<的问题~
#include<iostream>#include<cstring>
using namespace std;
class Stu{
char name[20];
float score;
public:
Stu(char *p,float s){
strcpy(name,p);
score=s;
}
Stu(){
score=0;
strcpy(name,"no name");
}
void set(char *p,float s){
strcpy(name,p);
score=s;
}
friend ostream & operator << (ostream &os, Stu&x) ;
};
ostream & operator << (ostream &os, Stu &x){
os << "name" << x.name << "\tscore" << x.score <<endl;
return os;
}
int main(){
Stu x("Xuu",93.5);
cout << x;
return 0;
}
为什么总是出错啊~高手帮忙~