help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: std::vector in the union


From: Torsten Müller
Subject: Re: std::vector in the union
Date: 25 Jul 2002 06:41:18 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Stephane Routelous <address@hidden> writes:

> I'm using yacc to parse a file.
>
> In my case, I would like to include some vectors from stl in the union.
> But, I can't because, in a union, you cannot have members with copy
> constructors.

Right. Another problem are destructors. There are two ways to work
around this: use use global variables or - better - use pointers to
STL containers. The following union would work right:

> typedef union
> {
> int iVal;
> double fVal;
> std::vector<MyObject*>* objectsVal;
> } YYSTYPE;

The vector is stored as pointer. A problem is cleaning up (deleting
the vector and its elements), especially in an error case. But in
practise this works very well.

Torsten




reply via email to

[Prev in Thread] Current Thread [Next in Thread]