Wrong C++ of the day

#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;
}

4 Responses to “Wrong C++ of the day”

  1. CheesyRobMan says:

    And for those of us who don’t speak spod, what does this mean?

  2. Topper says:

    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.

  3. Chris says:

    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)

  4. Lori says:

    Geek! 🙂