Help improve this code

you need to define action() before it is used. (so move it up in the listing or use a separate .cpp file for it)