Re: virtual function jumptable
George Neuner wrote:
On Fri, 28 Aug 2009 17:55:17 CST, srp113
<sunilsreenivas2001@yahoo.com> wrote:
... I want to build a jump table (lets say a simple
array) that maps an event(integer) to a member function pointer:
jumptable[eventid]->fptr(eventdata).
a)Will jumptable[eventid]->fptr(eventdata) work as expected? ( esp
for virtual functions will this call the most derived classes
implementation?),
It will work as expected, but probably won't do what you want. The
pointer in the table will specify which function is called - there
will be no inheritance.
Pointers to member functions behave polymorphically.
b)Is there a performance penalty with this implementation (going
through 2 lookups one for jump table and then for vtable)?
There will only be one lookup, but yes, there will be a penalty.
Calling a member function through a pointer to member function is much
more complex than calling a function directly. The runtime code has to
resolve inheritance hierarchies, which the compiler would do for a
direct call.
This has all been addressed in responses to the same question on
comp.lang.c++.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]