Added code for visitor pattern, fixed compile issues.

you can just create the visitor locally. no need to make it a pointer to parent.