Boost logo

Boost Users :

From: Cory Nelson (phrosty_at_[hidden])
Date: 2004-11-14 21:08:43


boost.variant :)

On Sun, 14 Nov 2004 17:54:51 -0500, Jeffrey Holle
<jeff.holle_at_[hidden]> wrote:
> Something like:
>
> class Data
> {
> Data(float item) : type(float),float_datum(item) {}
> Data(uint32_t item) : type(uint32_t),uint32_datum(item) {}
> private:
> enum { float, uint32_t} type;
> union {
> float float_datum;
> uint32_t uint32_datum;
> };
> }
>
> This is called an anonymous union.
> The caviot is C++ does allow classes within unions. Its because the
> compiler wouldn't know which default constructor to call...
> If you need to handle classes, its time to start using pointers too.
>
>
>
> Stephen torri wrote:
> > On Sun, 2004-11-14 at 10:42 -0500, Jeffrey Holle wrote:
> >
> >>You can't use templates in this manner.
> >>Ask yourself, which type of Data object do you expect boost.graph to
> >>instanciate when a new vertex is created? It can only make one choice.
> >
> >
> > I know that this was broken. I made the declaration that it was.
> >
> >
> >>If I was doing this, and was concerned about memory consumption, I'd
> >>consider using a union attribute in Data, along with a type attribute.
> >
> >
> > Can you provide a simple example using the two types I gave in this
> > example: float and uint32_t?
> >
> > Stephen
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Cory Nelson
http://www.int64.org

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