旧 C++ 版本中结构和 class 之间的区别

Difference between struct and class in older c++ versions

在 C++ 中,classstruct 是否总是只有默认访问说明符不同?或者在某些早期版本中,C++ struct 更像是 C struct?

几乎总是。

早在标准化之前就是这样,

令人沮丧的是,Stroustrup's "A History of C++" does not discuss this, but types known as "classes", defined using the struct keyword, could be found as early as "The C++ Programming Language - Reference Manual",这是“C with 类”研究阶段之后的第一个规范,因此实际上是第一个准标准 C++ 修订版:

classes containing a sequence of objects of various types, a set of functions for manipulating these objects, and a set of restrictions on the access to these objects and functions;

structures which are classes without access restrictions

这被称为“版本 E”,came in November 1984

到 1989 年Release 2.0,这已经放宽到我们今天的规则:

structures which are classes without default access restrictions

作为时间参考,我们现在称为“C++”的第一个版本是在 1998 年标准化的。

按照标准,是的,在实践中我也听说编译器试图(或仍在尝试?)通过优先考虑不同的优化路径来在内部以不同方式处理它们。