PHcoDer PHcoDer - 1 year ago 131
C++ Question

C++: Calling a function from derived by a function pointer defined in base class

If a function pointer is defined and assigned values in base class. And it has to be used to call a function from a class derived from it. How can we do that?

This shows an example to call functions by pointers. But this works only in case when pointer is defined in same class from where it is being used.

This shows example to call parent class function. I tried some this similar but it didn't work.

From derived

Both of the above doesn't work. Please help me out.

Answer Source

Simply use:


Nothing else is required. Cast to base type is implicit. So you do not need to cast it explicitly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download