N
Nashirak
I am trying to implement callbacks in C++. I am modeling my callbacks
after some of the stuff that was done in wxWidgets (if anyone is
familiar with that). The syntax is as follows:
// Header
DEFINE_NAMESPACE_BEGIN(NGMX)
typedef void (PI_PluginAPI::*KMKeyboardMethod)(const KeyboardEvent
*event);
class KM_Keymap : public PI_PluginAPI
{
public:
KM_Keymap();
// More functions follow ....
bool AddKeymapEntryMethod(const char *top_entry, const char
*name,const char *desc, PI_PluginAPI *obj, KMKeyboardMethod func, void
*userdata=NULL);
private:
// Private stuff here
};
DEFINE_NAMESPACE_END
Then I have a calling class. It structure is as follows:
// Header
class My_Plugin : virtual public NGMX:I_PluginAPI
{
public:
My_Plugin();
// More stuff ...
void ShowStuffCB(const NGMX::KeyboardEvent *event);
private:
// Private stuff
};
To connect the callback I make this call in a method inside of the
My_Plugin (My_Plugin class uses the NGMX namespace up top) class:
// In source
m_keymap->AddKeymapEntryMethod("BASE","Show Stuff","Turn on and off
Stuff",this,(KMKeyboardMethod)&My_Plugin::ShowStuffCB);
Now the error I am getting is as follows (in Visual Studio 2003):
error C2664: 'NGMX::KM_Keymap::AddKeymapEntryMethod' : cannot convert
parameter 5 from 'void (__thiscall My_Plugin::* )(void)' to
'NGMX::KMKeyboardMethod'
Types pointed to are unrelated; conversion requires reinterpret_cast,
C-style cast or function-style cast
So it appears that it doesn't like the &My_Plugin::ShowStuffCB
parameter. My_Plugin inherits from PI_PluginAPI so I don't know why
the cast doesn't work. I am not sure what I am doing wrong. Anyone see
something glaring that needs to be fixed? Thanks in advance for you
help.
after some of the stuff that was done in wxWidgets (if anyone is
familiar with that). The syntax is as follows:
// Header
DEFINE_NAMESPACE_BEGIN(NGMX)
typedef void (PI_PluginAPI::*KMKeyboardMethod)(const KeyboardEvent
*event);
class KM_Keymap : public PI_PluginAPI
{
public:
KM_Keymap();
// More functions follow ....
bool AddKeymapEntryMethod(const char *top_entry, const char
*name,const char *desc, PI_PluginAPI *obj, KMKeyboardMethod func, void
*userdata=NULL);
private:
// Private stuff here
};
DEFINE_NAMESPACE_END
Then I have a calling class. It structure is as follows:
// Header
class My_Plugin : virtual public NGMX:I_PluginAPI
{
public:
My_Plugin();
// More stuff ...
void ShowStuffCB(const NGMX::KeyboardEvent *event);
private:
// Private stuff
};
To connect the callback I make this call in a method inside of the
My_Plugin (My_Plugin class uses the NGMX namespace up top) class:
// In source
m_keymap->AddKeymapEntryMethod("BASE","Show Stuff","Turn on and off
Stuff",this,(KMKeyboardMethod)&My_Plugin::ShowStuffCB);
Now the error I am getting is as follows (in Visual Studio 2003):
error C2664: 'NGMX::KM_Keymap::AddKeymapEntryMethod' : cannot convert
parameter 5 from 'void (__thiscall My_Plugin::* )(void)' to
'NGMX::KMKeyboardMethod'
Types pointed to are unrelated; conversion requires reinterpret_cast,
C-style cast or function-style cast
So it appears that it doesn't like the &My_Plugin::ShowStuffCB
parameter. My_Plugin inherits from PI_PluginAPI so I don't know why
the cast doesn't work. I am not sure what I am doing wrong. Anyone see
something glaring that needs to be fixed? Thanks in advance for you
help.