I have defined this struct:
typedef struct WHEATHER_STRUCT
{
unsigned char packetID[1];
unsigned char packetSize[2];
unsigned char subPacketID[1];
unsigned char subPacketOffset[2];
...
} wheather_struct;
How can I initialize this struct (using constructor or new) accessing by an attribute name? For example:
wheather_struct.packetID = 1;
Finally
I tried this solution and it works for me, but do you think it is a good choice?
WHEATHER_STRUCT * wheather_struct = new WHEATHER_STRUCT();
*weather_struct->packetID = '1';
And for a float attribute:
wheather_struct->floatAttribute= 111.111
mallocin C++.malloc? What's wrong with using constructors, andnew?mallocin a C++ program? If any of those members ofWEATHER_STRUCTchange to non-POD types, thatmalloccall will not create the object and you now have to hunt down a hard-to-find bug.newdoes?