Access a singleton instance with a preprocessor macro

Sometimes you encounter C++ code where a macro / #define is used to access a singleton. For example:

// the problem macro
#define InterfaceManager CInterfaceManager::Get()
template <typename t_Class>
class CSingletonT 
{
public:
    static inline t_Class& Get() 
    {
        static t_Class s_Instance;
        return s_Instance;
    }
};
class CInterfaceManager : public CSingletonT<CInterfaceManager>
{
public:
    void DoSomething()
    {
        m_iIndex = 5;
    }
protected:
    int m_iIndex;
};

If you try to access the singleton in your code by simply using the macro InterfaceManager, Visual Assist will not suggest anything. This happens because Visual Assist does not evaluate as you reference symbols, only when you define them. The workaround is to add the macro definition to the Visual Assist StdAfx.h file. Add the entry:

#define InterfaceManager CInterfaceManager::Get()

at the bottom. This file is used to help the Visual Assist parser with difficult code, and can be used to work around odd effects. After modifying this file, you need to rebuild the Visual Assist symbol database for the change to take effect: