Suppose that I have a class that has only int, char and so on, I mean, does not has any pointer or class. Could I use the reinterpret class to pack it to send through a network? My problem is that the sizeof operator, used to limit the buffer size, does not alway return the true size of the class. Example:
Thanks any help!Code:class Z{ public: //... private: int a; char b; }; int main(){ char* buffer; Z myClass; int size = sizeof(Z); //here the size will be 8, not 5 buffer = new char[size]; buffer = reinterpret_cast<char *>(&myClass); //any send routine //send(buffer, size, slave); return 0; }