#include <iostream> int gFoo = 0; int myOtherFunction(int); int myFunction(int a) { return a+1; } int myOtherFunction(int b = myOtherFunction(gFoo)) { return myFunction(b); } int main(void) { gFoo++; std::cout << myOtherFunction() << std::endl; }
#include <iostream> int gFoo = 0; int myOtherFunction(int); int myFunction(int a) { return a+1; } int myOtherFunction(int b = myOtherFunction(gFoo)) { return myFunction(b); } int main(void) { gFoo++; std::cout << myOtherFunction() << std::endl; }
And for those of us who don’t speak spod, what does this mean?
Imagine trying to wipe your arse using a hand protuding from the aforementioned arse. It’s the C++ equivalent of that. Ish. It’s certainly as sick and wrong.
Or, a less unpleasant way of putting it is that imagine you’ve got a recipe for a cake, which, as the first step says ‘First, make a cake’.
It’s not quite as recursive as it first appears – if you put a call to myOtherFunction() as the default parameter for b, it doesn’t compile.
(The gFoo stuff is just in there for added nastiness, and to confirm it doesn’t rely on compile-time constants to evaluate the default parameters)
Geek! 🙂