Function Pointers


Usage of function pointers in cpp


function_pointer.h
// 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);


function_pointer.cpp
// Functions:
class_A::fkt_AAAA(type1 value) {

// ......

}

class_A::fkt_BBBB(type1 value) {

// ......

}


main.cpp
...
if (true)
fpFkt = &class_A::fkt_AAAA;
else
fpFkt = &class_A::fkt_BBBB;


// call to fkt_AAAA(1000)
(this->*fpFkt)(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
(*pStateMatrixFunctions[Zeile][Spalte])();





Siehe auch C

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

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