
using namespace std;
void display(const student *const);
struct student
{
char name[20];
int age;
char sex[10];
};
int main()
{
student theclass[3]=
{
{"zhao",20,"male"},
{"li",21,"female"},
{"wang",13,"male"},
};
student *p=theclass ;
for (int i=0;i<3;i++)
display(p++);
return 0;
};
void display (const student * const st)
{
cout<
cout<
cout<
}
在使用自己定义的羡陆埋数据结兄蚂构之前一定要先声明。
“void display(const student *const);“写在struct student 的定义之前,编译器在前面找不到它的定义肯定要报错了。
只要把函数悉埋声明写在struct student{....}之后就行了:
struct student{}
void display(const student *const);
#include
using namespace std;
struct student
{
char name[20];
int age;
char sex[10];
};
void display(const student *const);//唯一的改动,把这句从struct student前移到了这里,因为如果你伍掘慧放在前面,编译器会不知道student为何物
int main()
{
student theclass[3]=
{
{"zhao",20,"male"},
{"li",21,"female"},
{"wang",13,"腔答male"},
};
student *p=theclass ;
for (int i=0;i<3;i++)
display(p++);
return 0;
};
void display (const student * const st)
{
cout<
cout<
cout<<散悄st->sex;
}