Struct VS Class

Jun 2, 2009 at 2:46pm
closed account (S6k9GNh0)
After some massive research into the Struct and Class, I've found them to be extremely similar. Apparently, how they manage memory and how they function is very similar. I've also seen arguments stating the only difference is that the Struct delcares members public by default and Class declares them private. So my question: What's the point of using a struct at all? Is the Struct simply a lower-level feature?
Last edited on Jun 2, 2009 at 2:47pm
Jun 2, 2009 at 2:52pm
Classes and structs are entirely equal except for the fact that a class's members are private by default, and a struct's members are public by default.

Structs exist so a C++ compiler can compile C.
Jun 2, 2009 at 3:40pm
closed account (S6k9GNh0)
The way everybody made it sound, it felt like it was at least different. :/

Marking solved but wouldn't mind more feedback.
Jun 2, 2009 at 3:49pm
closed account (z05DSL3A)
There is not much more to be said.

Here it is from the standard:
A structure is a class defined with the class-key struct; its members and base classes (clause 10) are public
by default (clause 11). A union is a class defined with the class-key union; its members are public by
default and it holds only one data member at a time (9.5). [Note: aggregates of class type are described in
8.5.1. ] A POD-struct is an aggregate class that has no non-static data members of type non-POD-struct,
non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator
and no user-defined destructor. Similarly, a POD-union is an aggregate union that has no non-static data
members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no userdefined
copy assignment operator and no user-defined destructor. A POD class is a class that is either a
POD-struct or a POD-union.
Section 9.0 paragraph 4 of Programming languages — C++ [ISO/IEC 14882, 2003]
Last edited on Jun 2, 2009 at 3:49pm
Topic archived. No new replies allowed.