www.digitalmars.com         C & C++   DMDScript  

c++ - Casting method pointers

reply "Charles Sanders" <sanders-consulting comcast.net> writes:
Hey all, Ill just post the code and the error first:

// WindyLib.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "windy.h"
#include "msg.h"


// Foward declarations of functions included in this code module:
class MyApp : public WindyApp , public MsgSlot {
public:

 void sayHello() { WindyApp::messageBox("hello"); }

 virtual void OnBegin() {
  CommandMsgSlot *msg = new CommandMsgSlot( &MyApp::sayHello) );

  Wnd* w= new Wnd("My Window");
  if (!w->createEx( WS_EX_CLIENTEDGE,"The title of my
window",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,NULL,
NULL, WindyApp::globalInstance, NULL))
   WindyApp::messageBox(WindyApp::getLastError() );
  //w->addHandler(WM_LBUTTONDOWN, );
  w->showWindow(true);

 }



};


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
  // TODO: Place code here.


 MyApp app;
 app.run();

 return 0;
}



The error :

C:\Projects\Windy\VC\WindyLib\WindyLib.cpp(16) : error C2664: '__thiscall
CommandMsgSlot::CommandMsgSlot(void (__thiscall MsgSlot::*)(void))' : cannot
convert parameter 1 from 'void (__thiscall MyApp::*)(void)' to 'void
(__thiscall MsgSlot::*)(void)
'
        Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast


My Question is how can I cast MyApp::functionPointer to MsgSlot::function
pointer ??  MyApp is derived from MsgSlot.

Thanks!
C
Nov 06 2003
parent "Charles Sanders" <sanders-consulting comcast.net> writes:
Nm I got it thx.

"Charles Sanders" <sanders-consulting comcast.net> wrote in message
news:boef51$1nol$1 digitaldaemon.com...
 Hey all, Ill just post the code and the error first:

 // WindyLib.cpp : Defines the entry point for the application.
 //

 #include "stdafx.h"
 #include "windy.h"
 #include "msg.h"


 // Foward declarations of functions included in this code module:
 class MyApp : public WindyApp , public MsgSlot {
 public:

  void sayHello() { WindyApp::messageBox("hello"); }

  virtual void OnBegin() {
   CommandMsgSlot *msg = new CommandMsgSlot( &MyApp::sayHello) );

   Wnd* w= new Wnd("My Window");
   if (!w->createEx( WS_EX_CLIENTEDGE,"The title of my
 window",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,NULL,
 NULL, WindyApp::globalInstance, NULL))
    WindyApp::messageBox(WindyApp::getLastError() );
   //w->addHandler(WM_LBUTTONDOWN, );
   w->showWindow(true);

  }



 };


 int APIENTRY WinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
                      LPSTR     lpCmdLine,
                      int       nCmdShow)
 {
   // TODO: Place code here.


  MyApp app;
  app.run();

  return 0;
 }



 The error :

 C:\Projects\Windy\VC\WindyLib\WindyLib.cpp(16) : error C2664: '__thiscall
 CommandMsgSlot::CommandMsgSlot(void (__thiscall MsgSlot::*)(void))' :
cannot
 convert parameter 1 from 'void (__thiscall MyApp::*)(void)' to 'void
 (__thiscall MsgSlot::*)(void)
 '
         Types pointed to are unrelated; conversion requires
 reinterpret_cast, C-style cast or function-style cast


 My Question is how can I cast MyApp::functionPointer to MsgSlot::function
 pointer ??  MyApp is derived from MsgSlot.

 Thanks!
 C
Nov 06 2003