繁体   English   中英

为什么即使在我尝试声明它之后,我的代码仍然说它具有不完整的类型?

[英]Why does my code say that it has an incomplete type even after I tried declaring it?

我正在编写一个程序,该程序以表格的形式显示许多学生的考试成绩,然后计算并显示平均值。 运行代码后,我收到以下错误(也如下图所示):变量的类型不完整 'struct student' struct Students st[50]; ^ 注意:'students' struct student st[50] 的前向声明;

我已经声明了学生并尝试声明了 st ,但我不确定问题是什么。 以下是我的代码的输入版本和屏幕截图:

#include <iostream>
using namespace std;
int Main()
{
  int students;

   struct students st[50]; 
   return 0;
}

代码错误键入代码的图片

本声明中学生使用的结构

struct students st[50];

尚未定义。 因此编译器会发出错误,因为您可能未声明元素类型不完整的数组。

你必须先定义它。 您也可以使用这种样式。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM