DEV Community

Discussion on: A Functional-Style State Machine in C++

Collapse
 
psydevascender profile image
Serge

Here's my 50 cents ) About the recursive function types.
I tried this, and it seems to work - because all function pointers should have the same machine size, regardless of their return type:

include

using FPTR = void * ()(int,float); // function-returning-void

FPTR function(int a,float b) // function, returning FUNCTION-POINTER (to function which itself returns-void* :)
{
std::cout << a*b;
return (FPTR)function;
}

int main() {
FPTR fp = (FPTR)function;
FPTR fp2 = (FPTR)fp(2,3.f);
(*fp2)(2,4.f);
}