Because #ifdef (and defined) only works for macros that has been defined using #define. I think you might be able to accomplish what you want using templates (SFINAE) but I don't know how.
Separating "meta-levels" is the trickiest part of metaprogramming, IMO. It can be difficult to remember what code runs when. The preprocessor operates on text, before the compiler touches your code, before anything (save preprocessor macros) are defined.
I think you might be able to accomplish what you want using templates (SFINAE)
these is for my global functions macro. it must have them, but don't means that i must define them all.
your sample: too much code for i control it :(
i must learn more about them
With the risk of stating the obvious, I just want to make it clear that the decision on which function to call is handled at compile time, so you cannot use the method shown by mbozzi to make runtime decisions based on the object's dynamic type when using pointers or references.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// ....
struct Base
{
};
struct Derived : Base {
void MouseClick() const;
};
int main()
{
Derived obj;
click(obj); // This will call Derived::MouseClick().
Base& ref = obj;
click(ref); // This will call the global ::MouseClick() function.
}