I don't know if my title is expressed with the right terminology, if it isn't, please correct me so I can update it. However this is my question expressed with code examples: What is the difference, when it comes to the keyStates variable, between example A and B?
Example A (Where the "keyStates" variable is defined as a static variable in the class in the .h file):
// Input.h
class Input
{
public:
static bool GetKeyDown(KeyCode keycode);
private:
static std::unordered_map<KeyCode, KeyState> keyStates;
}
// Input.cpp
#include "Input.h"
bool Input::GetKeyPressed(KeyCode keyCode)
{
for (auto Code : AllKeyCodes)
{
if (Code == keyCode)
{
return KeyState::PRESSED == keyStates.find(Code)->second;
}
}
return false;
}
Example B (Where the "keyStates" variable is defined without static in the .cpp file):
// Input.h
class Input
{
public:
static bool GetKeyDown(KeyCode keycode);
}
// Input.cpp
#include "Input.h"
std::unordered_map<KeyCode, KeyState> keyStates;
bool Input::GetKeyPressed(KeyCode keyCode)
{
for (auto Code : AllKeyCodes)
{
if (Code == keyCode)
{
return KeyState::PRESSED == keys.find(Code)->second;
}
}
return false;
}