Deklarieren eines Arrays von Zeigern auf Funktionen in Visual C++

Originalversion des Produkts:   Visual C++
Ursprüngliche KB-Nummer:   30580

In diesem Artikel wird das Deklarieren eines Arrays von Zeigern auf Funktionen in Visual C++ erläutert. Die Informationen in diesem Artikel gelten nur für nicht verwalteten Visual C++-Code.

Der folgende Beispielcode veranschaulicht das Erstellen eines Arrays, das Funktionsadressen enthält, und das Aufrufen dieser Funktionen.

/*
 * Compile options needed: none
 */

#include <stdio.h>

void test1();
void test2();            /*  Prototypes */
void test3();

/* array with three functions */
void (*functptr[])() = { test1, test2, test3 } ;

void main()
{
   (*functptr[0])();    /*  Call first function  */
   (*functptr[1])();    /*  Call second function */
   (*functptr[2])();    /*  Call third function  */
}

void test1()
{
   printf("hello 0\n");
}

void test2()
{
   printf("hello 1\n");
}

void test3()
{
   printf("hello 2\n");
}