1001010.com

one zero zero one zero one zero dot com
one hundred ten ten dot com
binary representation of ascii 'J' (74) dot com

home code projects photos wiki resumé tombstone ?
Individual Entry Archive: The Experiments of Jason De Arte - Evil Lawn Dart Master, Toy Maker and Professional Software Engineer
« prev: intitializing a static member of a template class
» next: Where's my 6Ghz Pentium something-or-other?
Code | Tuesday
Inititializing static class members
Posted by Jason on Tuesday October 04, 2005 09:41 AM  |  Permalink  |  Comments (0)

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]

Comments (0)

Comments are closed