www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - Casting method pointers

↑ ↓ ← "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
↑ ↓ → "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))' :

 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