A set of function pointers grouped into a data structure are often referred to as a virtual function table (VFT).
The above statement makes me feel that virtual function == function pointer
,is that so?
There is no built-in support for virtual functions in C.
In C++ virtual functions are specified via a v-table. And the entries in a vtable can be implemented as function pointers.
That’s wrong because these are different levels of abstraction.
An analogy may help: saying that virtual functions and function pointers are identical is like saying that wheels and bikes are identical.
While it’s true that function pointers and virtual functions may look much the same “under the hood”, they are different things – both conceptionally (a virtual function is an overriable member method of a class while a function pointer is simply an indirection of a function) and syntactically (calling them is completely different).
They may serve the same purpose, however. In particular, both provide a means of deferring a calling decision (which function to call in this situation?) until runtime when normal call dispatching happens at compile time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With