Boost logo

Boost Users :

Subject: Re: [Boost-users] variant: bounded types derive from same base class
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2009-08-03 13:31:54


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_at_[hidden]>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
>
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net