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.
ClassGetName()
#undef GetClassName
#include
them. I would rename the method.
Of course one can say
#include <windows.h>
#undef GetClassName
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):
TI_GetClassName()
TI_GetBaseClass()
TI_IsDerivedFromClass()
etc
2) or put them into some IClass interface
interface IClass {
GetName();
GetBase();
IsDerivedFrom();
etc
and return that interface from single method,
so that GetClassName() becomes
GetClass()->GetName()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With