Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

daerid

What the hell am I doing wrong?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Oh, and I''m using Visual C++ 6.0, Service Pack 5

"Doomed to crumble, unless we grow, and strengthen our communication" - Maynard James Keenan, Tool

Share this post


Link to post
Share on other sites
quote:
Original post by daerid
...

Ok, so then I add a cast:


win->AddMsg(new MsgHandler(WM_DESTROY,(MsgDispatch)MyWin::OnDestroy));
[/source]

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!




I already tried that. :\

"Doomed to crumble, unless we grow, and strengthen our communication" - Maynard James Keenan, Tool

Share this post


Link to post
Share on other sites
One problem from what you posted with the cast is that you''re missing a closing parenthesis. If that''s not how it shows up in your code, the error sounds like a scope problem.

Sorry about the last reply, didn''t finish reading the post.

Share this post


Link to post
Share on other sites
''sall right.

I double checked the parens, so that''s not the problem.

Hep!

"Doomed to crumble, unless we grow, and strengthen our communication" - Maynard James Keenan, Tool

Share this post


Link to post
Share on other sites
GAH

WTF

Ok, found it.

My Typedef is expecting a long as the 3rd param instead of a long&

Thanks anyways guys.

"Doomed to crumble, unless we grow, and strengthen our communication" - Maynard James Keenan, Tool

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!