I''m getting a weird error.
Ok, I''m trying to do some c++ Win32 stuff.
Here''s the important source:
class Window;
typedef bool (Window::*MsgDispatch)(unsigned int wparam,long lparam,long &retVal);
struct MsgHandler
{
unsigned int _msg;
MsgDispatch _pfn;
MsgHandler(unsigned int msg = 0, MsgDispatch pfn = 0)
: _msg(msg), _pfn(pfn) {}
};
class Window
{
// .. yadda yadda constructor, blah
public:
void AddMsg(MsgHandler *mh)
{
_msghandlers.push_back(mh);
}
protected:
auto_vector<MsgHandler> _msghandlers; // auto vector is a class template that is basically an array of std::auto_ptr''s
};
Ok, so that compiles fine. Above is basically just a framework for handling windows messages.
I get into trouble when I actually try to use the above code:
class MyWin : public Window
{
public:
bool OnDestroy(unsigned int wparam,long lparam,long &retVal);
};
bool MyWin::OnDestroy(unsigned int wparam,long lparam,long &retVal)
{
::PostQuitMessage(0);
retVal = 0;
return true;
}
// Just stub code for now
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR szCmdLine, int iShowCmd)
{
MyWin *win;
// ... blah blah... create window here
win->AddMsg(new MsgHandler(WM_DESTROY,MyWin::OnDestroy));
return 0;
}
It LOOKS fine to me, but when I compile, I get this error msg:
error C2664: ''__thiscall MsgHandler::MsgHandler(unsigned int,bool (__thiscall Window::*)(unsigned int,long,long))'' : cannot convert parameter 2 from ''bool (__thiscall My*)(
unsigned int,long,long &)'' to ''bool (__thiscall Window::*)(unsigned int,long,long)''
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Ok, so then I add a cast:
win->AddMsg(new MsgHandler(WM_DESTROY,(MsgDispatch)MyWin::OnDestroy));
And now I get this error:
error C2440: ''type cast'' : cannot convert from '''' to ''bool (__thiscall Window::*)(unsigned int,long,long)''
None of the functions with this name in scope match the target type
What am I missing? Is this not the correct way of doing this kind of thing?
This has been driving me nuts for a week. Help please!
"Doomed to crumble, unless we grow, and strengthen our communication" - Maynard James Keenan, Tool