Obtaining base class type

Hey everyone, I'm using wxWidgets, and as you all may know they have a silly macro used to define an event table... BEGIN_EVENT_TABLE( MainWindow, wxFrame ) EVT_CLOSE( MainWindow::OnClose ) END_EVENT_TABLE() I spend a few hours finding out that wxFrame is the incorrect parameter for parameter #2. This is not the base class that MainWindow derives from. There was no compiler error or warning, nor any errors during runtime. Only weird behavior because events were getting skipped. Because of this error-proneness, I'm looking for a way to have boost help me out with this. I'm looking for a metafunction in Boost that can be used to obtain (at compile time) the base type of MainWindow. For example: BEGIN_EVENT_TABLE( MainWindow, boost::get_base_of<MainWindow>::type ) EVT_CLOSE( MainWindow::OnClose ) END_EVENT_TABLE() Something like that above. I know that type traits has is_base_of, and I'm hoping there is a get version of that too. I've browsed through the reference but I've found nothing helpful.

Hmm now that I think about it, I don't think this is really possible at
compile time. You have to consider issues like multiple bases (Through
either a linear chain of inheritance, or multiple inheritance cases).
If there were only a way to simplify this. Specifying the base class in two
places is obviously error-prone, and I am hoping there are other solutions
to cleaning this up.
On Tue, Jun 9, 2009 at 1:36 PM, Robert Dailey
Hey everyone, I'm using wxWidgets, and as you all may know they have a silly macro used to define an event table...
BEGIN_EVENT_TABLE( MainWindow, wxFrame ) EVT_CLOSE( MainWindow::OnClose ) END_EVENT_TABLE()
I spend a few hours finding out that wxFrame is the incorrect parameter for parameter #2. This is not the base class that MainWindow derives from. There was no compiler error or warning, nor any errors during runtime. Only weird behavior because events were getting skipped.
Because of this error-proneness, I'm looking for a way to have boost help me out with this. I'm looking for a metafunction in Boost that can be used to obtain (at compile time) the base type of MainWindow. For example:
BEGIN_EVENT_TABLE( MainWindow, boost::get_base_of<MainWindow>::type ) EVT_CLOSE( MainWindow::OnClose ) END_EVENT_TABLE()
Something like that above. I know that type traits has is_base_of, and I'm hoping there is a get version of that too. I've browsed through the reference but I've found nothing helpful.

Robert Dailey wrote:
Hmm now that I think about it, I don't think this is really possible at compile time. You have to consider issues like multiple bases (Through either a linear chain of inheritance, or multiple inheritance cases).
This is what I call "upward introspection" and I think it downright impossible. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 09 June 2009, Robert Dailey wrote:
Hmm now that I think about it, I don't think this is really possible at compile time. You have to consider issues like multiple bases (Through either a linear chain of inheritance, or multiple inheritance cases).
If there were only a way to simplify this. Specifying the base class in two places is obviously error-prone, and I am hoping there are other solutions to cleaning this up.
It sounds like is_base_of and BOOST_STATIC_ASSERT would be enough to catch the errors at least? That is, you could make your own macro that does the type checking before passing the arguments on to BEGIN_EVENT_TABLE.
On Tue, Jun 9, 2009 at 1:36 PM, Robert Dailey
mailto:rcdailey@gmail.com> wrote: Hey everyone, I'm using wxWidgets, and as you all may know they have a silly macro used to define an event table...
BEGIN_EVENT_TABLE( MainWindow, wxFrame ) EVT_CLOSE( MainWindow::OnClose ) END_EVENT_TABLE()
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkousm0ACgkQ5vihyNWuA4V4qQCg2FAMkeaXPLyPgUUWdDQFP7wr KVsAoII3kgShdySIk7yvA8QOgiI/XmQI =f+pv -----END PGP SIGNATURE-----

On Tue, Jun 9, 2009 at 2:05 PM, Frank Mori Hess
It sounds like is_base_of and BOOST_STATIC_ASSERT would be enough to catch the errors at least? That is, you could make your own macro that does the type checking before passing the arguments on to BEGIN_EVENT_TABLE.
This actually won't work because technically wxWindow and wxFrame are both base classes of MainWindow. The difference is the number of "hops" between them. For example, wxWindow is further away from MainWindow in the inheritance diagram than wxFrame, but I don't think there is any way to measure this at compile time. Looks like I may just have to suck it up.
participants (3)
-
Frank Mori Hess
-
joel
-
Robert Dailey