So i'm working on a simple win32 wrapper for my own convenience, and i've run into a slightly complicated problem.
this has alot of other members, but i'm omitting a bit and leaving just the offending members.
class Windows::AbstractWindow
{
public:
void InstallHandler(UINT msgName, void (Windows::AbstractWindow::*)(HWND, UINT, WPARAM, LPARAM));
private:
std::map<UINT, void (Windows::AbstractWindow::*)(HWND, UINT, WPARAM, LPARAM)> HandlerIndex;
};
(for the record, Windows in this case is a namespace of various classes and objects i've made)
just a bit nasty but lemme explain my process and reasoning. i have a made a class called AbstractWindow which contains most of all of the functionality of a window in a very object oriented way.
I'm now working on a method of taking private member functions, and storing them in a map via pointers to them, which are identified by the Windows message that they are supposed to handle. This way, when a message is received by the windows procedure, it digs through this map to see if you've installed a handler for it. If it has it calls that function and exits. It it hasn't it calls DefWindowProc and exits. easy enough.
However, this object is never supposed to be instantiated and is simply supposed to be inherited from and extended. problem is, that map's function pointer declaraction is of type AbstractWindow which will not allow me to store member function pointers of a type inherited from AbstractWindow. For example,
class BasicWindow : public Windows::AbstractWindow
{
public:
BasicWindow()
{
InstallHandler(WM_CREATE, &create);
}
private:
void Create(HWND, UINT, WPARAM, LPARAM) {}
}
... yields an error:
error C2664: 'Windows::AbstractWindow::InstallHandler' : cannot convert parameter 2 from 'void (__thiscall BasicWindow::* )(HWND,MSG,WPARAM,LPARAM)' to 'void (__thiscall Windows::AbstractWindow::* )(HWND,UINT,WPARAM,LPARAM)'
because the pointer types are not the same, despite being inherited from the base class. So does anyone wish to suggest a solution while still maintaining this method? And if not, i'm also open to suggestions that you think would make message handling more convenient than this way.