/ * See ILOVENET masterpiece "Do you have tried the function as a parameter (PARAMETER)?" (Http://www.9cbs.net/develop/read_article.asp?id=18162). Quite feelings, below My "function pointer" and practical content as a parameter pass, don't say, everyone personally realizes it. I am limited, welcome to correct (never modest ^ _ ^). If there is any mistake, mailto: leepyzh@21cn.com/
// The program is as follows // Test on window 4 2000 VC 6.0 / / ==================================== =
#include "stdafx.h"
Typedef Bool (INT, INT); // Function Pointer // CompFunc means: / * Pointing to the return value is a function pointer compFunc a ====== Bool (* a) (int, int) * /
// Two simple functions, perform the opposite function BOOL LittleTletobig (Int A, int b) {Return B a;
Void Exchange (INT & A, INT & B) {INT TEMP; TEMP = a, A = B, B = TEMP;
// The pointer of the function is sorted by argument // any array // When it is incoming LittleTletobig, from a small to large, the BigTolittle is from the small to small
// The two function declaration methods are the same. #if 0void sort (int Array [], Const Int, Bool (* Comp) (int, int, int, int (; i INT Main (int Argc, char * argv []) {int Arr [] = {3, 4, 2, 1, -1, 999, 234, 34, 56, -2, -2}; // function pointer declaration, four The situation is exactly the same ///// ============================================================================================================================================================================================================= CompFunc Up = LittleTletobig, Down = Bigtolittle; Sort (Arr, SizeOf (Arr) / SizeOf (int), UP); Sort (Arr, SizeOf (Arr) / SizeOf (int), Down); ======= =================================================== BOOL (* up2) (INT) , INT = LittleTletobig; BOOL (* DOWN2) (INT, INT); DOWN2 = BigTolittle; Sort (Arr, SizeOf (Arr) / SizeOf (int), UP2); Sort (Arr, Sizeof (arr) / sizeof ), DOWN2); ============================================== ==== CompFunc Funcarray [2] = {LittleTletobig, Bigtolittle}; Sort (Arr, SizeOf (Arr) / SizeOf (int), Funcarray [0]); Sort (Arr, Sizeof (arr) / sizeof (int), Funcarray [1]); ========================================================= bool (* Funcarray2 [2]) (int, int) = {littletobig}; funcarray2 [1] = BigTolittle; Sort (Arr, SizeOf (arr) / sizeof (int), funcarray [0]); sort (Arr, Sizeof) Arr) / sizeof (int), Funcarray [1]); ===================================== ============= rurn 0;} ///// Reference to http://www.9cbs.net/develop/read_article.asp?id=18162./////