Why do both struct and class exist in C++?
如我们所知,
A POD struct109 is a non-union class that is both a
trivial class and a standard-layout class, and has no non-static data
members of type non-POD struct, non-POD union (or array of such
types). Similarly, a POD union is a union that is both a trivial
class and a standard-layout class, and has no non-static data members
of type non-POD struct, non-POD union (or array of such types). A POD
class is a class that is either a POD struct or a POD union.
在过度简化的情况下,在以下情况下,
- "类"的声明
- 作用域枚举类型的声明
- 详细的类型说明符,除非"class"是用
union 声明的
但是,在模板声明中不能显式使用
1 | template <struct T> // error |
我看不出
[class]/8 A standard-layout struct is a standard-layout class
defined with the class-key struct or the class-key class. A
standard-layout union is a standard-layout class defined with the class-key union.
在引入明显的不一致性的同时,这看起来相当冗长和混乱。
我有两个问题:
我是否遗漏了明显区分
这种笨拙背后的原因是什么,如果有的话?
我忽略了默认访问说明符之间的区别,因为每个人都已经知道了。
Why do both struct and class exist in C++?
存在
那么,"c with classes"为什么会引入新的关键字
Confusingly, the keywords themselves do not necessarily correspond to the language used in the standard
需要理解的是,类的概念与关键字
声明类有三个关键字。这些被称为类键的关键字是
However, struct explicitly cannot be used in a template declaration to introduce type template parameters
C++在不同的上下文中使用不同目的的关键字。类声明上下文中的
在模板类型参数的上下文中重用
你可能会问,为什么
I'm unable to see any significant difference between struct and class
很好。除了什么都没有?
This seems rather redundant and confusing while introducing a glaring inconsistency.
我看不出标准的引用有任何不一致之处。我看到了冗余,我怀疑冗余的存在是为了更加清楚地表明,用关键字
Are there any technical differences that I have missed that significantly distinguish struct and class?
我已经回答过了,但是很明显,用
?与默认访问说明符的区别(正如您已经知道的,这里也描述了),这是它们唯一的区别。
Why do both struct and class exist in C++?
EDCOX1〔0〕来源于C,主要存在于C++中,与C语言兼容。
Are there any technical differences that I have missed that
significantly distinguishstruct andclass ?
模板参数中使用的关键字
至于为什么不能使用