为什么C ++有一个“;”后的类声明 [英] Why does C++ have a ";" after a class declaration
问题描述
我开始学习C ++,出于好奇,为什么C ++要求你放一个;在类声明结束时
例如:
I'm starting to learn C++ and just out of curiosity, why does C++ require you to put a ";" at the end of the class declaration for example:
class A
{
/*...*/
};
在Java等语言中,它用于表示语句的结尾。
In languages like java, it's used to signify an end of a statement.
int i(5);
和上面的类关于C ++中的分号编译器将类视为语句还是对其有不同的解释?
and the class above with regards to the semi-colon in C++? Does the compiler treat the class as a statement or does it have a different interpretation for it?
推荐答案
,因为您也可以在声明中定义变量:
because you can also define variables in the declaration:
class A {
...
} x, y, z;
在分号中结束类声明基本上明确说明我们不是 声明此类型的任何变量。
Ending class declarations in a semicolon is basically saying explicitly that we are not declaring any variables of this type.
这篇关于为什么C ++有一个“;”后的类声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!