In what scenarios is it better to use a struct
vs a class
in C++?
they're the same thing with different defaults (private by default for class
, and public by default for struct
), so in theory they're totally interchangeable.
so, if I just want to package some info to move around, I use a struct, even if i put a few methods there (but not many). If it's a mostly-opaque thing, where the main use would be via methods, and not directly to the data members, i use a full class.