以下是什么bar
和x
,为什么它们位于此处?它们是struct
的实例吗?
我正在阅读此Stackoverflow question,粘贴了我的代码,发现海报和答案之一使用了bar
定义后的变量名[x
和struct
]。 cpp reference在其示例中未使用此语法,并且我不知道该语法是什么,也不知道该语法是做什么的。
如果只是创建struct
的实例,为什么不像cpp reference在其示例中那样在下一行中编写它呢?
struct _bar_
{
int a;
} bar;
struct test {
int value;
} x;
最佳答案
struct test { int value; } x;
声明x
为struct test
类型的对象。这是一个简单的声明,与int x
相同,只是用struct test { int value; }
代替int
。