Have you tried to pass the function as a parameter? (recommend)

zhaozj2021-02-17  47

When we pass the parameters of the function, we generally think of some things such as int, char, and pointers, references.

Have you ever thought about passing another function as a parameter to call a function?

Perhaps this feature is relatively used, but it is really effective.

Take a look at the example below

Bool Up (int A, int b) {RETURN B a;} void sort (int Array [], const int size, bool (* comp) (int, int))

// See clearly, the above is a function of a function {. . . // You can sort any array} then, you can call this.

Sort (MyIntarray, MyIntarraysize, UP);

Think about it, see if there is any other purpose, such as recurrence of headache.

转载请注明原文地址:https://www.9cbs.com/read-29123.html

New Post(0)