Look what I dug out of my mailbox. Did anything ever come of this? Angus
---------- Forwarded Message ---------- Subject: Visitor ... Date: Fri, 14 Dec 2001 05:15:44 +0000 From: John Levon <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] here's a working example of what Ben had designed (did this so I could work out what he was saying :) Dunno about others, but I prefer the name of visitInset to stay the same no matter what ... the two problems ben has been trying to fix with this (accompanied by stupid questions from myself) are : 1) each inset has to be listed in InsetVisitor 2) each inset HAS to have an acceptVisitor() method I still think it's worth it, even better if anyone can solve either of these problems ... regards john #include <iostream> class Inset; class InsetERT; class InsetVisitor { // blah blah public: // need every possible inset listed here // for dynamic dispatch based on inset type, // to be robust against future visitor classes virtual void visitInset(Inset &) {}; virtual void visitInset(InsetERT &) {}; }; class Inset { // blah blah public: virtual void acceptVisitor(InsetVisitor & iv) { iv.visitInset(*this); } }; class InsetERT : public Inset { // blah blah private: // need this here to get the right type for visitInset virtual void acceptVisitor(InsetVisitor & iv) { iv.visitInset(*this); } }; class SpellCheckInsetVisitor : public InsetVisitor { public: virtual void visitInset(Inset &) { // do default spellcheck std::cout << "default spellcheck" << std::endl; } virtual void visitInset(InsetERT &) { // don't do any spellcheck !! std::cout << "ert no spellcheck" << std::endl; } // this is the top-level code void doSpellcheck() { //for_each(bv.inset_iterator_begin(), bv.inset_iterator_end(), acceptVisitor(this)); Inset * ie = new InsetERT; ie->acceptVisitor(*this); } }; int main() { SpellCheckInsetVisitor v; v.doSpellcheck(); }