Hello in one of my current projects I want to implement an InputMap. So I have an abstract input
//Input.h
namespace INPUT {
class InputMap;
class Input {
public:
Input();
virtual ~Input();
virtual void Dispatch( InputMap * pMap ) = 0;
};
}
and an InputMap
//InputMap.h
namespace INPUT {
class InputMap {
public:
InputMap();
virtual void HandleInput( INPUT::Input & anInput ) {
}
virtual ~InputMap();
};
}
so far so good - no functionality here. Now I derive my first real Input from my abstract input class:
//StringInput.h
#include "Input.h"
#include "InputMap.h"
#include <string>
class StringInput : INPUT::Input {
public:
StringInput();
virtual ~StringInput();
void Dispatch(INPUT::InputMap * pMap)
{
pMap->HandleInput( *this );
}
void SetMessage(std::string message);
std::string GetMessage() const;
private:
std::string m_message;
};
and here is my derived InputMap
//MyInputMap.h
#include "InputMap.h"
#include "StringInput.h"
class MyInputMap: public INPUT::InputMap {
public:
MyInputMap();
void HandleInput( StringInput & anInput );
void HandleInput( INPUT::Input & anInput );
virtual ~MyInputMap();
};
and here is the test:
//main.cpp
MyInputMap map;
StringInput input;
input.SetMessage("Test");
input.Dispatch(&map);
of course I expect that input.Dispatch(&map)
invokes map.HandleInput(StringInput input)
, but unfortunately the default handler is always invoked. Did I program this pattern wrong? Thanks guys, I have been staring my code forever, but I don't see it.