ITEM 14. Function Pointers

xiaoxiao2021-03-05  25

Item 14. Function Pointers

Function pointer declaration: void (* fp) (int); // Brackets can not be omitted, removed, return type void *

Use: 1, when the address of the initialization or assignment function pointer A is the function pointer B, no need to explicitly take the address, the compiler will do it for you: Extern void h (int); fp = h; // ok, pointing H fp = & h; // ok 2, when the modified function pointer does not need to be probed, the compiler will do: (* fp) (12); // OK Explicitted FP (12); // OK implicitly 3, no universal function pointer can point to any type of function Non-static member function is not a pointer, so you can't point the function pointer to it 4, the function pointer is often used in the callback technology 5, when pointing the inline function When the inline modifier has been invalidated

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

New Post(0)