在C++中,class
和struct
仅在默认访问说明符之间总是不同吗?还是在某些早期版本的C++中,struct
更像C struct
?
最佳答案
几乎总是如此。
从标准化practically since the first draft revisions in the 80s到很久以前就是这种方式。
令人沮丧的是,Stroustrup's "A History of C++"并未对此进行讨论,但是使用struct
关键字定义的称为“类”的类型最早可以在"The C++ Programming Language - Reference Manual"上找到,它是“C with Classes”研究阶段之后的第一个规范,因此实际上是第一个-标准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年进行了标准化。
关于c++ - 旧版C++版本中struct和class之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62796837/