I have a question about C++ standard, I know a class is compatible with C if does not have any methods, but I'd need to have some getters (mainly not to forget various htoi and friends)
This is an example: is a class like
// declared in .hpp file
#pragma pack(1)
class c_something{
public :
int a;
char b[56];
boolean c;
WORD d;
inline std::string getBAsString(){ return std::string(b); }
inline uint16_t getD(){ return htons(d);}
}
compatible with the "C" type defined as a struct
// declared in an old C library header (.h)
#pragma pack(1)
typedef struct t_something{
//public :
int a;
char b[56];
boolean c;
WORD d;
} something, *pSomething;
My goal is to:
// in my new code I use the data provided by the old interface as a class
BYTE rawRecivedData rrd[56]; // a stream of data recived from the network
t_something data = (t_something) (*rrd);
printf("d value is %u", htons(data.d));
/* or just c_something *i = (c_something) (*rrd) */
c_something i = (c_something) data;
std::cout << i.std::string getBAsString() << "D:"<< i.getD() <<std::endl;
Have the C++ class wrap the C class: