From: Stefan S. <se...@sy...> - 2004-06-08 13:02:29
|
Christophe Avoinne wrote: > class NodeVisitor > { > ... > template< typename Class > > void operator( const Node< Class > &node ) > { ... // doing your stuff according with Class } > ... > }; > > As you can see, no derivation at all. but what problem does the above solve ? The idea was to use the visitor pattern, which means to call some kind of polymorphic 'accept' method on the 'Node' object, and its implementation will then call back with the exact type: struct FooNode : NodeBase { virtual void accept(Visitor *v) { v->visit_Foo(this);} }; It's the polymorphic 'accept' that requires 'FooNode' to be part of a class hierarchy of Nodes, not the 'visit' (or operator (), or however you spell it). Regards, Stefan |