error C2679

来源:百度知道 编辑:UC知道 时间:2024/06/07 03:47:52
#include <iostream.h>
const int n=5;
struct stu
{
char num[5];
int score;
};
void fun(stu a[])
{
stu max=a[0];
for(int i=0;i<n;i++)
if(a[i].score>max.score)
max=a[i];
cout<<max<<endl;
}
void main()
{
stu a[n]={{"a01",81},{"a02",88},{"a03",65},{"a04",76},{"a05",66}};
fun(a);

}

没有定义“struct stu”。
你的结构体写错了,正确应该是这样:
struct <结构体名>
{
<成员定义1>
<成员定义2>
.
.
<成员定义n>
}[结构变量名表];
结构体变量的初始化的一般形式是在变量后面加上:
={<初始列表>};
例如
struct POINT{
int x;
int y;
}spot={20,40};
结构体变量的引用只能是下列格式:
<结构体变量名>.<成员变量名>
例如
cout<<spot.x<<spot.y;