I have a small question to the singleton pattern using C++. Let's say I have the following class:
namespace MyNameSpace { class Window_Singleton { private: static Window_Singleton instance; Window_Singleton(); /* Some more private stuff here */ public: static Window_Singleton *GetInstance(); ~Window_Singleton(); /* Some more public stuff here */ } } #define Window Window_Singleton.GetInstance() I have this #define so that I don't always have to write MyNameSpace::Window_Singleton.GetInstance().SomeMethod(), I can now use the shorter MyNameSpace::Window.SomeMethod().
But the problem is: Now I cannot make a Window-class in another namespace because I will get problems with the define.
Is there a way to provide the #define without "breaking" my namespace. Some sort of "namespace-local" define?
#define"break" your namespace is not to use a#definehere. You mainly obfuscate your code with it, just dont do it and you wont have the problemWindow.SomeMethod()easier to read thanWindow.GetInstance().SomeMethod()?MY_NS_WINDOWwould probably stop it from clashing with other tokens.