This is a well-established and canonical reference question that in C ++, structures and classes are largely interchangeable when writing code manually.
However, if I want to link existing code, can I expect it to have any meaning (i.e. break, nose daemons, etc.) if I re-create the structure as a class or vice versa in the header after Was the original code created?
So, the situation is that the type was compiled as a structure (or class), and I then change the header file to another declaration before including it in my project.
The real use case is that I automatically generate code using SWIG, which generates different output depending on whether they are given by structures or classes; I need to change one to the other in order to get it for the correct interface.
An example here (Irrlicht, SVertexManipulator.h) is this:
struct IVertexManipulator { };
I update it mechanically as:
class IVertexManipulator {public: };
The source library compiles with the original headers intact. The wrapper code is created using modified forms and compiled using them. Then they are combined into the same program for collaboration. Suppose I use the same compiler for both libraries.
Is it something like undefined? "Undefined" but expected to work with real-world compilers? Absolutely permissible?
Other similar changes that I make include removing some default values ββfrom the parameters (to prevent ambiguity) and removing declarations from several classes where the type does not appear in SWIG (which changes the structure of the class, but my reasoning is that the generated code should need this information, only for reference to member functions). Again, how much harm could this have caused?
eg. IGPUProgrammingServices.h :
s32 addHighLevelShaderMaterial( const c8* vertexShaderProgram, const c8* vertexShaderEntryPointName, E_VERTEX_SHADER_TYPE vsCompileTarget, const c8* pixelShaderProgram=0, ...
CIndexBuffer.h :
public:
... and so on. Other changes include replacing some types of template parameters with their typedefs and removing the packed attribute from some structures. Again, it seems like there should be no problem if the modified structure declarations are never used in machine codes (just to generate names to refer to access functions in the main library), but how reliable is this? Ever been up?