A good situation where you might need a pointer to a function is in initialization... Andre Lamothe explains this really well in his book "Windows Game Programming"
Say for instance implementation of a fucntion depended of the video card
Code:
void SetPixel( int card, int x, int y)
{
switch( card )
{
case ATI: SetPixelAti(x,y); break;
case VOODO: SetPixelVoodoo(x,y); break;
case NVIDIA: SetPixelNvidia(x,y); break;
}
}
..the case would have to be evaluated each time you set a pixel...
..the switch is slow... and prone to error... you could also break it
each time you add a new card.. according to Lamothe
...what if instead upon initization you determined what type of video card this system had
Code:
void Init(){
int card = GetVideoCard();
switch( card )
{
case ATI: SetPixel = SetPixelAti; break;
case VOODO: SetPixel = SetPixelVoodoo; break;
case NVIDIA: SetPixel = SetPixelNvidia; break;
}
}
...now each time you want to set a pixel...
you just calll SetPixel( x, y ) and it knows which function to use...
..certainly the user will not be able to change video cards in the midst of your program....
This can also work for OS dependent fucntions... for instance some methods work on say .... windows9x and not on NT/XP ...