Last updated:2026-10-12
C++ struct vs class Differences¶
About the Author:¶
Personal WeChat official account:

About struct in C and C++, see All About struct
Generally speaking, a struct is better seen as the implementation body of a data structure, while a class is better seen as the implementation body of an object.
Differences:
The most essential difference is the default access control
The default inheritance access permission: for a struct it is public, for a class it is private.
As the implementation body of a data structure, a struct's default data access control is public, whereas as the implementation body of an object, a class's default member variable access control is private.
Related Topics¶
- C++ Pure Virtual Functions and Abstract Classes | C++那些事
- C++ assert | C++那些事
- C++ Bit Fields | C++那些事
- Implementing C++ Polymorphism in C | C++那些事
- C++ const Constants and Qualifiers | C++那些事
- The Complete C++ const Family | C++那些事
- C++ Dereference Operator * | C++那些事
- C++ Initialization and Assignment | C++那些事
- Ways to Return Multiple Values in C++ | C++那些事
- C++ mutable Keyword | C++那些事