[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: std::vector in the union
From: |
Hans Aberg |
Subject: |
Re: std::vector in the union |
Date: |
Wed, 24 Jul 2002 19:24:51 +0200 |
At 11:13 -0400 2002/07/24, Stephane Routelous wrote:
>I'm using yacc to parse a file.
This is the Help Bison list.
>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.
I usually write a C++ polymorphic hierarchy, skipping the %union feature,
instead using a special %typed feature I implemented myself.
You can try the latest Bison Beta at
ftp://alpha.gnu.org/gnu/bison/
which supports C++; use the option -S c++.bison (or was it bison.c++?). --
The Bison development team haven't gotten as far as supporting polymorphic
hierarchies yet.
>typedef union
>{
...
>std::vector<MyObject*> objectsVal;
>} YYSTYPE;
>it doesn't work.
Even if it would have worked, it is a bad idea to use types without proper
constructors/destructors in C++ STL containers, because they were not
designed for it. So instead of std::vector<T*> write a my_pointer<T> class
and use std::vector<my_pointer<T> >.
At 17:28 +0200 2002/07/24, Akim Demaille wrote:
>| typedef union
>| {
...
>| std::vector<MyObject> *objectsVal;
> ^
>| } YYSTYPE;
This way, one looses the point of using C++, namely cleanup of dead objects.
So it is better to write a polymorphic hierarchy.
Hans Aberg