Class vs Struct for data only?

There is no real advantage of using one over the other, in c++, the only difference between a struct and a class is the default visibility of it’s members (structs default to public, classes default to private).

Personally, I tend to prefer structs for POD types and use classes for everything else.

EDIT: litb made a good point in the comment so I’m going to quote him here:

one important other difference is that
structs derive from other
classes/struct public by default,
while classes derive privately by
default.

Leave a Comment