Improve example C++ files

This fixes various issues in the C++ examples, to be more idiomatic and show good C++ style.