Was it always in C++ that class
and struct
are different only by the default access specifier? Or in some early version C++ struct
was more like C struct
?

- 16,127
- 7
- 34
- 62

- 201
- 1
- 8
-
This question applies to all versions of C++: [When should you use a class vs a struct in C++?](https://stackoverflow.com/questions/54585/when-should-you-use-a-class-vs-a-struct-in-c) – Aziz Jul 08 '20 at 14:15
-
I think here you can find a answer https://stackoverflow.com/questions/92859/what-are-the-differences-between-struct-and-class-in-c – bozali Jul 08 '20 at 14:16
2 Answers
Pretty much always.
It has been this way since long before standardisation, practically since the first draft revisions in the 80s.
Frustratingly, 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", which was the first specification following the "C with Classes" research phase and thus effectively the first pre-standard C++ revision:
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
This was known as "Release E", and came in November 1984.
By Release 2.0 in 1989, this had been relaxed to the rule we have today:
structures which are classes without default access restrictions
For a temporal reference, the first version of what we now call "C++" was standardised in 1998.

- 17,071
- 2
- 21
- 35
By the standard yes, in practice I too have heard that compilers attempted (or still attempt?) to handle them differently internally by prioritizing different optimization paths.

- 967
- 1
- 7
- 16
-
[Visual C++ mangles them differently, which results in some non-compliance.](https://stackoverflow.com/a/36917400/4386278) – Asteroids With Wings Jul 08 '20 at 14:35