类和结构后面的分号
可能的重复:
为什么我必须放C++ 中类声明末尾的分号?
找到 重复,请投票关闭。
为什么在 C++ 中类和结构必须用分号结束?
就像下面的代码一样:
class myClass
{
};
struct muStruct
{
};
这种语法在 Java 或 C# 中不是必需的。为什么 C++ 解析器需要它?
Possible Duplicate:
Why must I put a semicolon at the end of class declaration in C++?
Found duplicate, vote to close please.
Why do classes and structs have to be concluded with semicolon in C++?
Like in the following code:
class myClass
{
};
struct muStruct
{
};
This syntax isn't necessary in Java or C#. Why does the C++ parser need it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是为什么...
两条不同的语句,两种完全不同的含义,都是合法的C/C++,唯一的区别就是struct声明后的
;
。This is why...
Two different statements, two completely different meanings, both legal C / C++, and the only difference is the
;
after the struct declaration.因为
}
后面的下一个单词可能声明该类型的变量。这是 C 的遗物:Because the next word following the
}
may declare a variable of said type. This is a relic from C:以下内容在 C++ 中是合法的:
您需要分号来指示您不创建新实例。 C# 和 Java 的语言设计者显然并不认为允许这样做对他们的语言来说是一个有用的补充。
The following is legal in C++:
You need the semicolon to indicate you aren't creating a new instance. The language designers of C# and Java apparently didn't feel that allowing this was a useful addition to their language.