Declare an array of pointers to functions in Visual C++

文章推薦指數: 80 %
投票人數:10人

The sample code below demonstrates building an array that contains function addresses and calling those functions. C++. Copy. /* * Compile ... Skiptomaincontent Thisbrowserisnolongersupported. UpgradetoMicrosoftEdgetotakeadvantageofthelatestfeatures,securityupdates,andtechnicalsupport. DownloadMicrosoftEdge Moreinfo Tableofcontents Exitfocusmode ReadinEnglish Save Tableofcontents ReadinEnglish Save Edit Twitter LinkedIn Facebook Email Tableofcontents DeclareanarrayofpointerstofunctionsinVisualC++ Article 05/08/2022 2minutestoread 1contributor Inthisarticle Originalproductversion: VisualC++ OriginalKBnumber: 30580 ThisarticleintroduceshowtodeclareanarrayofpointerstofunctionsinVisualC++.TheinformationinthisarticleappliesonlytounmanagedVisualC++code. Thesamplecodebelowdemonstratesbuildinganarraythatcontainsfunctionaddressesandcallingthosefunctions. /* *Compileoptionsneeded:none */ #include voidtest1(); voidtest2();/*Prototypes*/ voidtest3(); /*arraywiththreefunctions*/ void(*functptr[])()={test1,test2,test3}; voidmain() { (*functptr[0])();/*Callfirstfunction*/ (*functptr[1])();/*Callsecondfunction*/ (*functptr[2])();/*Callthirdfunction*/ } voidtest1() { printf("hello0\n"); } voidtest2() { printf("hello1\n"); } voidtest3() { printf("hello2\n"); } Inthisarticle



請為這篇文章評分?