William Conrad Halliburton <[EMAIL PROTECTED]> writes:

> I have written code to call C++ code (via nm and demangling). Has anyone 
> done work on dynamic dispatching? Any pointers to relevant information 
> would be highly appreciated. How does C++ dyanamic dispatching work and 
> is it possible, with a pointer to a class, to call the correct member 
> functions?

Others have pointed out that this is all compiler-dependent, but every
c++ compiler I've worked with does dynamic dispatch basically the same
way.  Each object contains a pointer to the object's virtual function
table, which is just an array of function pointers correponding to the
virtual functions applicable to the object's class.  Since there's no
way for the compiler to know how big the object is at compile time, it
pretty much has to be at the top of the object.  It's up to you to
figure out which vtable entry corresponds to which function, but
hopefully it's something simple like the order in which they're
declared.  Write a little sample program and look at the disassembly.
It shouldn't be too hard unless you use multiple inheritance, in which
case all bets are off :)

Best wishes,

cbb

-- 
 18:49:55 up 30 days,  4:50,  2 users,  load average: 0.25, 0.27, 0.19

Reply via email to