18.8 Initialization and Ter mination 823
// contents of MyClass.cpp
Matrix2 Matrix2::TWICE_IDENTITY = Matrix2::IDENTITY*2.0f;
If the static matrix of MyClass is initialized first, the static matrix of Matrix2 has all
zero entries, since the storage is reserved already by the compiler but is set to zero
values as is all static data.
Problems can occur with file-static data. If a file-static pointer is required to
allocate memory, this occurs before the main application is launched. However, since
such an initialization is C-style and not part of class semantics, code is not generated
to deallocate the memory. For example,
int* g_aiData = new int[17];
int main ()
{
memset(g_aiData,0,17*sizeof(int));
return 0;
}
The global variable g_aiData is allocated premain, ...