Reputation: 233
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
?
Upvotes: 1
Views: 125
Reputation: 17474
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.
Upvotes: 6
Reputation: 1057
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.
Upvotes: 1