The differences between a class
and a struct
in C++ is:
struct
members and base classes/structs are public
by default.
class
members and base classes/struts are private
by default.
Both classes and structs can have a mixture of public
, protected
and private
members, can use inheritance and can have member functions.
I would recommend you:
- use
struct
for plain-old-data structures without any class-like features;
- use
class
when you make use of features such as private
or protected
members, non-default constructors and operators, etc.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…