When should you use a class vs a struct in C++?,
In what scenarios is it better to use a
struct vs a
class in C++?
The differences between a
class and a
struct in C++ is:
structmembers and base classes/structs are
classmembers and base classes/struts are
Both classes and structs can have a mixture of
private members, can use inheritance and can have member functions.
I would recommend you:
structfor plain-old-data structures without any class-like features;
classwhen you make use of features such as
protectedmembers, non-default constructors and operators, etc.
That’s the answer When should you use a class vs a struct in C++?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.
The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you