看龙书时看到函数指针
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
int d3d::EnterMsgLoop( bool (*ptr_display)(float timeDelta) ) { MSG msg; ::ZeroMemory(&msg, sizeof(MSG)); static float lastTime = (float)timeGetTime(); while(msg.message != WM_QUIT) { if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); } else { float currTime = (float)timeGetTime(); float timeDelta = (currTime - lastTime)*0.001f; ptr_display(timeDelta); lastTime = currTime; } } return msg.wParam; }
看下面一个简单的实例就明白了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include "stdafx.h" 2 # include <cstdio> 3 bool fun1(float min) 4 { 5 printf("%f ",min); 6 return 0; 7 } 8 void fun(bool (*ptr)(float min)) 9 { 10 ptr(3.14); 11 } 12 13 void main() 14 { 15 fun(fun1); 16 getchar(); 17 }