+ 1

Structures in c++?

I don't recall seeing structures in the c++ tutorial. did I miss it? Are classes generally used instead of structures?

15th Jan 2017, 4:12 PM
Zachery Mills
Zachery Mills - avatar
2 odpowiedzi
+ 6
Differences between a class and a struct in C++ are that structs have default public members and bases and classes have default private members and bases. Both classes and structs can have a mixture of public and private members, can use inheritance and can have member functions. So by this it's hard to answer your question directly as it depends entirely on what you are trying to achieve withe the code in question.
15th Jan 2017, 4:19 PM
Alex
Alex - avatar
0
structs are good for constrained systems where they can be composed only of PODs. The advantage is they can be immutable and initialised with curly braces. While equivalent to classes in all but default accessibility, naming PODs (which can still be classes) as structs improves readability (they betray their C heritage)
15th Jan 2017, 5:55 PM
Leon
Leon - avatar