预计……当我有一个时,在声明列表的末尾?
所以我声明了一个如下所示的结构,
struct location {
char occupier;
int points;
int x;
int y;
int current_x = PLAYER_STARTING_COL;
int current_y = PLAYER_STARTING_ROW;
};
我创建了一个名为starting的结构变量,但是,当我编译它时,我收到一个错误,说它需要在我的声明列表末尾有一个分号?有什么办法可以解决这个问题吗?我是 C 初学者,只需要一些帮助
struct location starting;
so i've declared a struct which is shown below
struct location {
char occupier;
int points;
int x;
int y;
int current_x = PLAYER_STARTING_COL;
int current_y = PLAYER_STARTING_ROW;
};
I have made a struct variable called starting however, when I compile it I get an error saying it expects a semicolon at the end of my declaration list? Is there any way I can fix this? I'm a beginner to C and just need a bit of help
struct location starting;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与 C++ 相反,在 C 中,您不能在定义中初始化结构的数据成员。
因此,当定义结构类型的对象时,您必须编写
并初始化数据成员,例如
如果上述声明是文件范围声明,则
PLAYER_STARTING_COL
和PLAYER_STARTING_ROW
必须是常量表达式。In C opposite to C++ you may not initialize data members of a structure in its definition.
So you have to write
and to initialize data members when an object of the structure type is defined as for example
If the above declaration is a file scope declaration then
PLAYER_STARTING_COL
andPLAYER_STARTING_ROW
must be constant expressions.