This question was already asked in the context of C#/.Net.
Now I\'d like to learn the differences between a struct and a class in C++. Please discuss the technical d
Member of a class defined with the keyword class
are private
by default. Members of a class defined with the keywords struct
(or union
) are public
by default.
In absence of an access-specifier for a base class, public
is assumed when the derived class is declared struct
and private
is assumed when the class is declared class
.
You can declare an enum class
but not an enum struct
.
You can use template
but not template
.
Note also that the C++ standard allows you to forward-declare a type as a struct
, and then use class
when declaring the type and vice-versa. Also, std::is_class
is true
for Y being a struct
and a class
, but is false
for an enum class
.