Skip to main content

Posts

Showing posts with the label virtual function

What are benefit of function pointer?

There are many many uses of function pointers ranging from simple ones to complex scenarios. One example in C++ domain is implementation of virtual functions using vtable. vtable is one of the methods to implement virtual functions in C++. This uses function pointers. Other good example are the scenario where you dynamically load a shared library. Once the application loads the library, it calls the functions defined in that library using function pointers. many of the sort algorithms take function pointer as an argument and call that function pointer to perform the comparison between two entities. At an enterprise level, an Application which is a transaction monitor (i.e which support online transactions), communication with difference databases using a well known standard called XA interface. This communication happens using function pointers. Advantage here is that the application need not be aware of how various databases implement their commit or rollback functions.