Want to use Global Variable to present instance-related value?

Sometimes we may need to use a global variable to present a value acting like a class member variable, but we couldn’t define it into the class header file (Don’t ask why because cross-platform developers may really have this kind of requirements).

The solution is simple: use a static map as the global variable.

For example, in the mm file:


static map<YourClassName*, bool> isUsingXFeature;


if (shouldUseXFeature())
   isUsingXFeature[this] = true;


if (isUsingXFeature[this]) 

Of course you can define the global variable as unordered_map to go a fancier way.