C++ 我发现数据结构有错误
编译器告诉我“student”“不引用某个值”这是我理解的student的错误。test引用某个值,并且该值已初始化为变量。我需要帮助C++ 我发现数据结构有错误,c++,data-structures,C++,Data Structures,编译器告诉我“student”“不引用某个值”这是我理解的student的错误。test引用某个值,并且该值已初始化为变量。我需要帮助 int main() { ifstream dataIn; ofstream dataOut; struct student{ string lastName=" "; string firstName=" "; int test1=0; int test2=0; int test3=0; int test4
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
)定义。student.test1
就像说string.length()
或如果stream您的student结构没有“average”和“total”的任何数据成员,但您正试图将它们用作调用averageScore函数的参数。我猜,您已经在“char grade='';”上方使用“};”将结构关闭到早期。