I just discovered from this Q/A that structs are inheritable in C++ but, is it a good practice, or is it preferable to use classes? In which cases is preferable and in which ones is not?
I have never needed this, but now I have a bunch of messages of different types, but same longitude. I got them in binary in a char array, and I just copy them with memcpy to the struct to fill its fields (I don't know if it is even possible to do it with std::copy).
I guess it would be great to be able to inherit every struct from a base struct with common headers, that is why I searched for this. So a second question would be: if I do this with classes, is it possible to do a memcpy (or std:copy) from a buffer to a class?
structthe default visibility ispublicwhile for classes it'sprivate.classandstruct, which affects inheritance specifically: The default mode of inheritance isprivatewithclass, butpublicwithstruct. So when you dostruct D : A, this will be the same asstruct D : public A. But that should not stop you from using inheritance withstructof course.