How to swap between functions implementation?

  • A+

Is there any way to swap between two functions implementation in C++ ?

Something like this:

void printA(); // print a char void printB(); // print b char  printA(); // output: a printB(); // output: b  functionSwap(printA, printB);  printA(); // output: b printB(); // output: a 

I want to use it with the ExitProcess function.


You can bind a pointer to both functions in two variables and swap those.

void (*f1)() = printA; void (*f2)() = printB;  f1(); // output: a f2(); // output: b  std::swap(f1, f2);  f1(); // output: b f2(); // output: a 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: