Wiki source for CFunctionPointer


Show raw source

====Function Pointers====

===Usage of function pointers in cpp===

%%(c;;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);
%%

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

// ......

}

class_A::fkt_BBBB(type1 value) {

// ......

}
%%

%%(c;;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

%%(c)
// 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 {{backlinks}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki