我在数据结构方面有错误



编译器告诉我"学生"不是指值",这是我理解的学生.test引用一个值,该值已经初始化为变量。我需要帮助

int main() {
ifstream dataIn;
ofstream dataOut;

struct student{
    string  lastName=" ";
    string firstName=" ";
    int test1=0;
    int test2=0;
    int test3=0;
    int test4=0;
    int test5=0;
   };
char grade=' ';
int total=0;
int average =0;
average=averageScore(student.test1, student.test2, student.test3,  student.test4,student.test5,student.average, student.total);

问题是struct student是一个类型定义,而不是一个变量声明。

因此,为了访问字段,您应该声明这种类型的变量,并使用变量而不是类,即:

student st;
char grade=' ';
int total=0;
int average =0;
average=averageScore(st.test1, st.test2, st.test3,  st.test4,st.test5,st.average, st.total);

(而且,正如黄先生提到的,平均字段不是为struct student定义的)

相关内容

最新更新