Memset should be used to initialize some simple pure data structures, such:
1, array, int A [100], float B [200]
2. struct composed of simple data types:
Struct
{
Int;
Float B;
Double C [100]
}
3. A single simple data can also be used.
Int;
Memset (& A, 0, sizeof ())
Memset should not be used for initialization for arrays composed of classes, but should be initialized in the class constructor.
For example, the cstring class of MFC
Cstring;
Cstring B = _ T ("ABC ");
Memset (& A, 0, sizeof ());
A = B; // sorry, an error occurred while running.
You used memset to destroy everything in.
Similarly, cstring STR [100] should not be initialized using memset.
The cstring constructor has already set the initial value to an empty string, saving memset.
If the class is defined by yourself, initialize it in the constructor instead of calling the memset function.