Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C++ socket sends out the garbled code of class members, seeking the guidance of God.
C++ socket sends out the garbled code of class members, seeking the guidance of God.
There are several questions:

First, sizeof is not used in this way, sizeof () is to calculate the size of data types such as sizeof(CSendPackage); ; You should use a function like strlen () to calculate the size of a string.

Second, some data members of CSendPackage cannot be sent, which can be seen from the copy constructor of the class.

Simply put, when there is a dynamic array in a class, you can't simply copy the class with the assignment equal sign (=). of course,

memcpy(& amp; pkg . subs & amp; subs,sizeof(subs)); This is even worse.

subs . m _ SubsID = " 123456 "; You can know. M_SubsID is a string or Cstring type, which uses a dynamic array to store string data. For example, Cstring only uses four bytes, and there is a pointer to the string. Send it.

Data pointed by all pointers in pkg will not be sent.