为什么我的代码在我尝试声明它之后仍然说它的类型不完整?
Why does my code say that it has an incomplete type even after I tried declaring it?
我正在编写一个程序,以 table 的形式显示一些学生的考试成绩,然后计算并显示平均值。根据 运行 代码,我收到以下错误(也如下图所示):
变量的类型不完整
'struct students'
构造学生 st[50];
^
注意:'students' 的前向声明
结构学生 st[50];
我已经声明了学生并尝试声明了 st,但我不确定问题出在哪里。以下是我的代码的打字版本和屏幕截图:
#include <iostream>
using namespace std;
int Main()
{
int students;
struct students st[50];
return 0;
}
Code errors
Picture of typed code
本声明中使用的结构学生
struct students st[50];
尚未定义。所以编译器会报错,因为你可能没有声明一个元素类型不完整的数组。
您应该先定义结构,然后再在数组声明中使用其详尽的名称,例如
include <string>
struct students
{
std::string name;
};
int main()
{
int students;
struct students st[50];
//...
}
你必须先定义它。你也可以使用这种风格。
struct student{
...
};
int main{
student* st[50];
for(int i=0; i<50;i++)
st[i]=new student;
return 0;
}
我正在编写一个程序,以 table 的形式显示一些学生的考试成绩,然后计算并显示平均值。根据 运行 代码,我收到以下错误(也如下图所示): 变量的类型不完整 'struct students' 构造学生 st[50]; ^ 注意:'students' 的前向声明 结构学生 st[50];
我已经声明了学生并尝试声明了 st,但我不确定问题出在哪里。以下是我的代码的打字版本和屏幕截图:
#include <iostream>
using namespace std;
int Main()
{
int students;
struct students st[50];
return 0;
}
Code errors Picture of typed code
本声明中使用的结构学生
struct students st[50];
尚未定义。所以编译器会报错,因为你可能没有声明一个元素类型不完整的数组。
您应该先定义结构,然后再在数组声明中使用其详尽的名称,例如
include <string>
struct students
{
std::string name;
};
int main()
{
int students;
struct students st[50];
//...
}
你必须先定义它。你也可以使用这种风格。
struct student{
...
};
int main{
student* st[50];
for(int i=0; i<50;i++)
st[i]=new student;
return 0;
}