Issue
In what scenarios is it better to use a struct vs a class in C++?
Solution
The differences between a class and a struct in C++ is:
structmembers and base classes/structs arepublicby default.classmembers and base classes/struts areprivateby 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
structfor plain-old-data structures without any class-like features; - use
classwhen you make use of features such asprivateorprotectedmembers, non-default constructors and operators, etc.
Answered By - Commodore Jaeger Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.