SharedMember optimization; moved forward decls.

SharedMember is now faster for upcasting (e.g. from
SharedMember<Derived> to SharedMember<Member>), since the whole dynamic
pointer cast isn't needed: Derived is always convertable to Member.

Moved forward declarations into types.hpp instead of having them in
various places.