In C++, classes and structs are very similar - the only technical difference is that class members are private by default, while struct members are public by default. However, the convention is to use them in slightly different scenarios:
Use structs when you have a simple data type that:
Examples include things like 2D/3D vectors, points, or color values.
Use classes for more complex types that:
Examples include things like a Player
class in a game, or a Database
class.
So in summary, prefer structs for simple "Plain Old Data" (POD) types, and classes for more complex types that resemble real-world objects with behaviors.
Answers to questions are automatically generated and may not have been reviewed.
A crash tour on how we can create custom types in C++ using classes, structs and enums