I have some code that has a dynamic-class system in C++ that has a member called GetClassName(), a rather harmless name one would imagine. However when included in a large project with Windows headers all hell broke loose. Apparently Windows uses a #define GetClassName (GetClassNameA or GetClassNameW) which screws up everything, and my virtual call tree became all messed up making me lose a day in stupid compiler debugging in the dark, trying to figure out what was wrong.
So besides the point that I’m cursing Microsoft for using such a horribly easy to clash name for a #define (I mean someone should honestly be shot for this!) I’m asking for 3 purposes.
- What’s another good name for GetClassName() ?
- Is there anyway to fix this, so in the future, other developers of my code base won’t suffer similar fate
- And for posterity when someone else encounters this similarly inexplicable error
I would rename the method.
Of course one can say
but it is not clean, users of one’s code should remember to write ::GetClassNameW when they call win32 function.
One can provide GetClassNameA and GetClassNameW methods in his class, but it’s plain ugly.
I see two approaches : either lengthen or shorten the name:)
1) add a prefix for all functions in the subsystem, f.e TI_ (for type info):
2) or put them into some IClass interface
and return that interface from single method,
so that GetClassName() becomes