调用结构体函数的问题
程序代码:#include<stdio.h>
#include<string.h>
void swap(struct student *a, struct student *b) {
struct student tmp;
tmp= *a;
*a = *b;
*b = tmp;
}
struct student
{
char name[16];
unsigned char age;
unsigned char score;
char classes[100];
};
int main()
{
struct student st[10] = { {"fei",12,66,"c++"} ,{"yuan",13,77,"hph"},
{"xu",13,44,"jave"}, {"fan",12,33,"c#"}, {"xun",23,44,"pathy"} };
int i;
int j;
for (i = 0; i < 5; i++) {
for (j = 1; j < 5 - i; j++) {
if (st[j].age < st[j - 1].age) {
swap(&st[j], &st[j - 1]);
}
}
}
for (i = 0; i < 5; i++) {
printf("name:%5s,age:%5d,score:%5d,classes:%5s\n", st[i].name,
st[i].age, st[i].score, st[i].classes);
}
getchar();
return 0;
}出现的问题是:
严重性 代码 说明 项目 文件 行
错误 C2079 “tmp”使用未定义的 struct“student” Project2 e:\qt\c++qt\project2\project2\源.cpp 4
严重性 代码 说明 项目 文件 行
错误 C2582 “operator =”函数在“student”中不可用 Project2 e:\qt\c++qt\project2\project2\源.cpp 6
严重性 代码 说明 项目 文件 行
错误 C2582 “operator =”函数在“student”中不可用 Project2 e:\qt\c++qt\project2\project2\源.cpp 7
严重性 代码 说明 项目 文件 行
错误 C2440 “=”: 无法从“student”转换为“int” Project2 e:\qt\c++qt\project2\project2\源.cpp 5
麻烦大家了




