================================== Declaration ==================================
The copyright of this article belongs to the author.
This article is original, reproduced must be prominently in the text of the author and source, and to ensure the integrity of the article (including this statement).
Do not modify (including this statement) without the authorization of the author, and reserve the right of legal investigation.
Do not use the academic citation without the author's authorization.
Do not use for commercial publishing, commercial printing, commercial references, or other commercial purposes without the authorization of the author.
=======================================================================
I've always felt that the function pointer and the function pointer array Nothing, until later I knew these things
Correct usage, that is to let! You! See! No! Understand!
=======================================================================
Here is my sample small code.
The first version of the typedef.
=======================================================================
function pointers
(Use function pointers as type definitions and initialize arrays)
#include <iostream>using namespace Std;int MyFunc1 (int p,int q) {return p%q;} int MyFunc2 (int p,int q) {return p/q;} int MyFunc3 (int p,int q) {return p-q;} typedef int (*PMF) (int,int); int main () { PMF arrpmf[3]={myfunc1,myfunc2,myfunc3}; int nres; NRES=ARRPMF[1] (7,2); cout<<nres<<endl; NRES=1[ARRPMF] (7,2); cout<<nres<<endl; return 0;}
Array of function pointers
#include <iostream>using namespace std;int MyFunc1 (int p,int q) {return p%q;} int MyFunc2 (int p,int q) {return p/q;} int MyFunc3 (int p,int q) {return p-q;} typedef int (*pmf[]) (int,int); int main () { PMF arrpmf={myfunc1,myfunc2,myfunc3}; int nres; NRES=ARRPMF[1] (7,2); cout<<nres<<endl; NRES=1[ARRPMF] (7,2); cout<<nres<<endl; return 0;}
From know C + + this thing to now barely able to write two lines of code, although over the years I have seen some very fantasy works, but suddenly saw
1[ARRPMF] (7,2);
I've been doing it for a while. Kill anyone is a must for home travel.
=======================================================================
If you do not have a good c/C + + foundation and the basic comprehend by analogy and widely associative small head melon seeds, you can basically "give up the speed of death."
(The line below is not code)
arrpmf[1]==>* (arrpmf+1) <==>* (1+ARRPMF) ==>1[ARRPMF]
=======================================================================
The most anticipated technique (Zuò) (sǐ) edition
Enjoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooy it!
#include <iostream>using namespace std;int MyFunc1 (int p,int q) {return p%q;} int MyFunc2 (int p,int q) {return p/q;} int MyFunc3 (int p,int q) {return p-q;} Int (*arrpmf[]) (int,int) ={myfunc1,myfunc2,myfunc3};//when the line is 108,000 from the point of call, La La. int main () { int nres; NRES=1[ARRPMF] (7,2);//Feel the deep malice of the arrogant universe cout<<nres<<endl; return 0;}
C + + Basics-Function pointer array