Hello Friends,

As we know, when we have virtual function in our class, compiler smartly puts vptr(virtual table pointer) in our class to access correct function at run time.
Can i access this vptr in my program, to use/manipulate this directly?

Regards,
Vivek

Hi,

That was an amazing article to go through & a great insight. Thanks alot for sharing this.
Can you share me more details :

1) Following is puzzling me:
( (void (*)()) vptr[0] )();

I am sure we can split this in multiple instrcutions to make it more user readable?
Can you help by splitting so that it is understandable to me?

2) I checked this program in "Microsoft Visual C++ 2005", but i could not get the value of "n", even if the __asm instructions are present. It seems "Microsoft Visual C++ 2005" does not use ECX register for this pointer. Is it so?

Regards,
Vivek

( (void (*)()) vptr[0] )();

This term...

((void(*)())

is a cast prefaced in front of this function pointer call...

vptr[0] )();

The function pointer call is calling a function at this address...

vptr[0]

...and the function itself is such that it takes no parameters, i.e., 'void', and returns nothing, i.e., return is void.

The cast in front of this function address is simply necessary to inform the compiler that,

a) it is a function pointer call that returns void;
b) it uses __cdecl;
c) it is a function pointer call and there are no parameters.

This article has been dead for over six months. Start a new discussion instead.