Boost logo

Boost :

From: Eric Friedman (ebf_at_[hidden])
Date: 2003-04-07 19:50:29

Gennadiy Rozental wrote:
> > > So the tradeoff here is extra 4 bytes for the object size plus double
> > > indirection for all access operations. Here the question arise then
> > not
> > > use virtual function based solution then? I bet it will be
> > more
> > > simple to understand and probably easier to use.
> >
> > I'm not quite sure how virtual functions will solve anything, but I am
> eager
> > to understand if indeed they will.
> >
> > Please explain.
> Well polymorphic objects is not that brand new idea in C++. We used to
> implement this kind of design using abstract based class with virtual
> function interface (unless we are using unions of course). This solution
> it's drawbacks and it's advantages (mostly simplicity to understand and
> use). So with above tradeoff in effect I question what would be more
> appropriate to use: boost::variant based solution or legacy one.

Your solution is noted in the variant docs ("Polymorphism: Inheritance vs.
Variants"), as well as its drawbacks. If you are concerned about efficiency,
a notable drawback is the need for dynamic allocation.

As is often the case, there are advantanges and drawbacks to any solution.
If you have suggestions to improve variant, I welcome them. Otherwise, I
think this conversation is finished.

 - Eric

Boost list run by bdawes at, gregod at, cpdaniel at, john at