• 12
• 12
• 9
• 10
• 13

# Method and function name conflict

This topic is 2766 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm in a bit of a trouble here. I have the following class:

#include <windows.h>class Input{    // ... not relevant code...    short GetKeyState(const KEY &key)    {        return m_keyState[key];    }    void Update()    {        for (int t=0; t<m_nKeys; t++)        {            // calls the Win32 GetKeyState function to retrieve key state            m_keyState[t] = GetKeyState(m_win32Key[t]);        }    }};

I can't compile it because C++ thinks that I'm calling Input::GetKeyState instead of Win32's global function.
Is there any way I can solve it without changing my method name?

##### Share on other sites
Try:
m_keyState[t] = ::GetKeyState(m_win32Key[t]);

##### Share on other sites
That worked. Thanks. I thought that :: would mean that I'm trying to access the closest function. I must have misunderstood it.

##### Share on other sites
The leading '::' means "look in the global namespace first".

##### Share on other sites
Be careful when overloading the Win32 functions. Anything dealing with strings will be re-#defined to a specific Unicode or ANSI function, depending on what you're compiling as. So, e.g., CreateWindow would be come CreateWindowA or CreateWindowW.

Anyway... In practice this usually causes trouble when attempting to overload such a function name in a header, where one module using the function includes <windows.h> and another doesn't, or where <windows.h> is included after your own header.