|
Re: Cooperative Visitor: A Template Technique for Visitor Creation
|
Posted: Apr 6, 2008 10:11 AM
|
|
Hi,
The vtable is indeed parameterized over the typelist. Here's the declaration for GetStaticVtable which creates shared vtables:
template< typename Visitor, typename VisitedList, typename Invoker > struct GetStaticVtable;
In your example, there would be a vtable shared by all instances of MyVisitor1 and another shared by all instances of MyVisitor2.
The vtable pointer, in this case Visitor<Shape,void>::vtable_, is a member variable. So changing the vtable pointer should be safe.
The vtable pointer can be changed by calling Visits again with a new invoker and/or new typelist (visited list). This coupled with the fact that any legal C++ code (say logging, traversal of sub-objects etc) can be put in invoker::invoke, provides dynamic configuration of visitation behavior.
Changing vtable pointer, doesn't affect existing vtables. A new shared vtable is created for the <Visitor, VisitedList, Invoker> triple.
|
|