[英]Why does my code say that it has an incomplete type even after I tried declaring it?
I am writing a program that displays a number of students test scores in the form of a table and then calculates and displays the average.我正在编写一个程序,该程序以表格的形式显示许多学生的考试成绩,然后计算并显示平均值。 Upon running the code, I get the following errors(also pictured below): variable has incomplete type 'struct students' struct students st[50];运行代码后,我收到以下错误(也如下图所示):变量的类型不完整 'struct student' struct Students st[50]; ^ note: forward declaration of 'students' struct students st[50]; ^ 注意:'students' struct student st[50] 的前向声明;
I have declared students and have tried declaring st and I am just not sure what the problem is.我已经声明了学生并尝试声明了 st ,但我不确定问题是什么。 Below is a typed version and a screenshot of my code:以下是我的代码的输入版本和屏幕截图:
#include <iostream>
using namespace std;
int Main()
{
int students;
struct students st[50];
return 0;
}
The structure students used in this declaration本声明中学生使用的结构
struct students st[50];
is not defined yet.尚未定义。 So the compiler issues an error because you may not declare an array with an incomplete element type.因此编译器会发出错误,因为您可能未声明元素类型不完整的数组。
You have to define it first.你必须先定义它。 You can also use this style.您也可以使用这种样式。
struct student{
...
};
int main{
student* st[50];
for(int i=0; i<50;i++)
st[i]=new student;
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.