| 1001010.com |
one zero zero one zero one zero dot com |
How many times have you heard that "you must initialize static class members in the .cpp file"?
When my team leader (Ray) saw my previous post he immediately said, "well we have put the initialization in the .cpp file".
I smirked.
That near pavlovian response is somehow ingrained in the c++ programmer's collective subconscious. I can see how, most of us were taught that the class and function definitions go into the .h file while the implementation goes in the .cpp file. And the initializing of static member would definitely fall into the category of initialization.
Have you ever even tried to do it in the .h?
Never? really? that doesn't surprise me. But did you know that it's done all over the place in the ATL?
Think about it - the ATL resides almost entirely in .h files. The exception being WinMain/DllMain exports and some calloc/realloc/free wrappers.
And there are static class members in there ...
They're initialized in the .h file ...
And they compile ...
[insert spooky Halloween music here]