Function Pointers

Usage of function pointers in cpp

// constructor of pointer to undefined function
void (class_A::*fpFkt)(type1 value);

// constructors of pointer to defined functions
class_A::fkt_AAAA(type1 value);
class_A::fkt_BBBB(type1 value);

// Functions:
class_A::fkt_AAAA(type1 value) {

// ......


class_A::fkt_BBBB(type1 value) {

// ......


if (true)
fpFkt = &class_A::fkt_AAAA;
fpFkt = &class_A::fkt_BBBB;

// call to fkt_AAAA(1000)

Usage of function pointers in c

Function pointer array example

// Array of function pointers
void(*pStateMatrixFunctions[4][4])(void) = {
    tr00,   error,  ignore, error,
    ignore, tr11,   tr12,   error,
    ignore, error,  tr22,   error,
    tr30,   error,  ignore, tr33        

// Call

Siehe auch C

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki