I have one question about using pragma in c++ classes. I've read there (Use of #pragma pack on a class) that use pragma around c++ class is not recommended, but can I use pragma like this:
class TestClass {
public:
ConfigProtocol();
#pragma pack(1)
struct t_config_header {
quint8 version;
quint8 da;
quint16 sa;
quint16 counter;
};
#pragma pack()
};
will not it be mistake?
Short answer: Yes you can (and in your case, as it seems you are implementing a communcation protocol, in fact, should) do it.
The way you are using the pragma is only affecting the structure which invalidates the arguments made in the StackOverflow answer you are linking to: The struct is not significantly changing as long as it stays a struct.