I want to define a structure in the C ++ source code, which should be POD (therefore, it must be compiled based on C, not C ++)
for example, suppose I have the following code inside a C ++ file:
struct myStruct { int x; int y; } class MyClass { int x; int y; }
If I compile this code, the struct will be a POD and should be compiled as a POD. Thus, the placement of member variables follows the C standard, which is well defined.
But suppose the user can erroneously change the code to this code:
struct myStruct { int x; int y; private: int z; } class MyClass { int x; int y; }
now the structure is not a POD, and the compiler is free of how it puts member variables into memory.
How to make the compiler make sure that the structure is always compiled based on the C standard?
Please note that I cannot put the code inside the * .c code, since I only develop header code that can be included in the * .cpp source code.
source share