主文件中定义了结构体如下
struct People {
string name;
int sex;
int age;
int phoneNumber;
string home;
};
在主函数中设计结构体数组
struct People peopleInformation[1000];
通过函数引用结构体数组地址
addPeople(peopleInformation);
头文件引用
#include<iostream>
using namespace std;
void addPeople(struct People p[]);
源文件引用
#include"addPeople.h"
void addPeople(struct People p[], int len, int i) {
cout << "姓名:";
cin >> p[i].name;
}
发生报错,使用了未定义类型“People”
解决方法,在源文件中加上结构体。
#include"addPeople.h"
struct People {
string name;
int sex;
int age;
int phoneNumber;
string home;
};
void addPeople(struct People p[], int len, int i) {
cout << "姓名:";
cin >> p[i].name;
}