Ambiguous conversions & multiple inheritance from classes that both
have wxEvtHandler
Volker Bartheld
dr_versaeg at freenet.de
Fri Mar 23 09:25:45 PDT 2007
Hi!
Please excuse if this probably is a DAU question. I have a base class that
inherits from wxEvtHandler to be able to handle some very basic custom
events, such as wxMY_EVT, i. e.
DEFINE_EVENT_TYPE(wxMY_EVT)
DECLARE_EVENT_TYPE(wxMY_EVT, -1)
class MyBase : public wxEvtHandler
{
DECLARE_ABSTRACT_CLASS(MyBase)
DECLARE_EVENT_TABLE()
public:
void OnMyCommand(wxCommandEvent& WXUNUSED(evt)) { };
virtual bool Foo()=0;
private:
};
IMPLEMENT_ABSTRACT_CLASS(MyBase, wxEvtHandler)
BEGIN_EVENT_TABLE(MyBase, wxEvtHandler)
EVT_COMMAND(wxID_ANY, wxMY_EVT, OnMyCommand)
END_EVENT_TABLE()
. Later, I wanted to add functionality from another wxW class:
wxTaskBarIcon, and implement additional handlers that should be known only
to the derived class, so I chose to inherit from MyBase *and*
wxTaskBarIcon:
class MyTaskbarIcon : public MyBase, public wxTaskBarIcon
{
enum tIDs { eMyCommandId=0x1 };
DECLARE_DYNAMIC_CLASS(MyTaskbarIcon)
DECLARE_EVENT_TABLE()
public:
void OnMyTaskbarIconCommand(wxCommandEvent& WXUNUSED(evt)) { };
virtual bool Foo() { return true; }
};
IMPLEMENT_DYNAMIC_CLASS2(MyTaskbarIcon, MyBase, wxTaskBarIcon)
BEGIN_EVENT_TABLE(MyTaskbarIcon, wxTaskBarIcon)
EVT_COMMAND(eMyCommandId, wxMY_EVT, OnMyTaskbarIconCommand)
END_EVENT_TABLE()
This resulted in
error C2594: 'return' : ambiguous conversions from 'MyTaskbarIcon *' to
'wxObject *'
error C2594: 'static_cast' : ambiguous conversions from 'void (__thiscall
MyTaskbarIcon::* )(wxCommandEvent &)' to 'wxCommandEventFunction'
which was clear since I had two wxObject* and two potential
wxCommandEventFunction in MyTaskbarIcon. Since I have no idea in how to
resolve this conflict, there was the other option in dynamically adding a
handler as descibed in "Cross-Platform GUI Programming with wxWidgets", p.
30ff and came up with
class MyTaskbarIcon : public MyBase, public wxTaskBarIcon
{
enum tIDs { eMyCommandId=0x1 };
public:
MyTaskbarIcon() : MyBase(), wxTaskBarIcon()
{
wxTaskBarIcon::Connect(eMyCommandId, wxMY_EVT,
wxCommandEventHandler(MyTaskbarIcon::OnMyTaskbarIconCommand));
}
void OnMyTaskbarIconCommand(wxCommandEvent& WXUNUSED(evt)) { };
virtual bool Foo() { return true; }
};
which kinda "fixed" the first error but not the second.
What's the general recommendation when inheriting from two classes that
both have wxObject and wxEvtHandler ancestors? Or is this a general no-no?
Thanks in advance for helping me out.
Volker
--
mailto: V B A R T H E L D at G M X dot D E
More information about the wx-users
mailing list