
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Ovanes Markarian Sent: 03 August 2009 18:32 To: boost-users@lists.boost.org Subject: Re: [Boost-users] variant: bounded types derive from same base class sorry, forgot to derive ABCDerived1 form ABCBase ;) But hope you got the intention. On Mon, Aug 3, 2009 at 5:33 PM, Ovanes Markarian <om_boost@keywallet.com> wrote: Hi! The only solution I can come up with is the declaration of the visitor in your ABCBase as virtual function and visitor has a function template to dispatch different types: class ABCVisitor { public: template<class T> void visit(T& t) { // no visit implemented ... } }; class ABCBase { //... dtor, copy ctor, assignment operator etc. public: void accept_visitor(ABCVisitor& v) { do_accept_visitor(v); } private: virtual void accept_visitor(ABCVisitor& v)=0; }; class ABCDerived1 : public ABCBase { //... dtor, copy ctor, assignment operator etc. void accept_visitor(ABCVisitor& v) { v.visit(*this); } }; template<> void ABCVisitor::visit<ABCDerived1>(ABCDerived1& derived) { // handle derived here... } Hope that helps, Ovanes ---------------------------------------------------------------------------- ----------------- Unfortunately, that would require changing the ABCBase to add those 2 member functions. I can't touch ABCBase nor Really, I have an existing hierarchy of classes which I cannot touch, but I still would like to have "external" polymorphism behaviour without the need to add base class virtual functions. Rds,