cppstudy: exercise for chapter8