- The function pointer is a type of pointer, when dereferenced, which invokes a function, passing it zero or more arguments just like a normal function.
- The function pointer make it possible that a function is selected to execute based on the run-time values. This can also be achieved by the virtual function in C++.
- The function pointer also makes it possible that a function caller could control the behavior of the function by passing it a function pointer. This is much better than passing it a flag.
- Java doesn't support the function pointer.
- The function pointer is less error prone than the normal pointers because you will never allocate or deallocate memory with them.
- C++ virtual functions are implemented with virtual table pointed by a vitual pointer. Actual the virtual pointer is the function pointer.
- A function pointer always points to a function with a specific signature. Thus all functions, you want ot use with the same function pointer, must have the same parameters and return-type.
Reference:
Function Pointer Tutorials: http://www.newty.de/fpt/index.html
No comments:
Post a Comment