为什么我必须在C ++的类声明的末尾添加一个分号? [英] Why must I put a semicolon at the end of class declaration in C++?
问题描述
在C ++类声明中:
class Thing
{
...
};
为什么必须包含分号?
完整的语法基本上是
class NAME {constituents}实例;
其中constituents是类元素和方法的序列,instances是类(即对象)的实例的逗号分隔列表。
示例:
class FOO {
int bar;
int baz;
} waldo;
声明类FOO和对象waldo。
实例序列可能为空,在这种情况下,您只需要
class FOO {
int酒吧;
int baz;
};
你必须把分号放在那里,以便编译器知道你是否声明了任何实例。 / p>
这是一个C兼容性的东西。
In a C++ class declaration:
class Thing
{
...
};
why must I include the semicolon?
The full syntax is, essentially,
class NAME { constituents } instances ;
where "constituents" is the sequence of class elements and methods, and "instances" is a comma-separated list of instances of the class (i.e., objects).
Example:
class FOO {
int bar;
int baz;
} waldo;
declares both the class FOO and an object waldo.
The instance sequence may be empty, in which case you would have just
class FOO {
int bar;
int baz;
};
You have to put the semicolon there so the compiler will know whether you declared any instances or not.
This is a C compatibility thing.
这篇关于为什么我必须在C ++的类声明的末尾添加一个分号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!