Can someone please give me a simple explanation of how to achieve or emulate run-time polymorphism in C.
Also, is this a valid example of runtime-polymorphism:
void fred(){
printf("Fred here!\n");
}
void john(){
printf("John here\n");
}
void barbara ( void (*function_ptr)() ){
(*function_ptr)();
}
int main(){
barbara (fred);
barbara (john);
return 0;
}
The function barbara dynamically calls either john()
or fred()
. Is this what runtime polymorphism exactly is?