[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Union Type Object problem
From: |
Laurence Finston |
Subject: |
Re: Union Type Object problem |
Date: |
Sun, 8 Aug 2004 17:23:54 +0200 (MEST) |
On Sun, 8 Aug 2004, Hans Aberg wrote:
> The problem is this: Suppose D is derived from base B, and you make void*
> conversions on D* and B*, how do you know how to get back a D* or B*, as
> that may vary dynamically. If you do it the proper way, you use B* and a D*
> is converted to a B* via a dynamic_cast<B*>.
>
> You could use a void* if you know that what it represents when you convert
> it back. But the whole idea of polymorphy is that is not available at
> compile time.
>
With respect to my parser, it's generally clear from the rules what
the type of an object is.
I use a `void*' because of the limitations of `union', not because I don't know
the types of the objects in question.
In the cases where the type of an object might be a base or derived class,
I use virtual functions and cast to the base class.
I haven't had to use `dynamic_cast()' in the parser. So far, I've
always been able to use `static_cast()'.
I've found that it's often more convenient to store information in the object
that I pass as a parameter to `yyparse()', so that sometimes I don't need to set
the semantic value of a rule, or that it's redundant. This is especially useful
for lists of options. If I rewrite my parser, or write another one for a
different purpose, I may just use `void*' as the semantic value for simplicity's
sake, unless a single type like `int' would do the job. Of course, somebody
who's bothered by explicit casts wouldn't like this solution.
Laurence
- Union Type Object problem, Enrico Oliosi, 2004/08/05
- AW: Union Type Object problem, Olav Groehn, 2004/08/05
- Re: Union Type Object problem, Hans Aberg, 2004/08/05
- Re: Union Type Object problem, Laurence Finston, 2004/08/05
- Re: Union Type Object problem, Laurence Finston, 2004/08/05
- Re: Union Type Object problem, Hans Aberg, 2004/08/06
- Re: Union Type Object problem, Laurence Finston, 2004/08/07
- Message not available
- Re: Union Type Object problem, Hans Aberg, 2004/08/09
- Re: Union Type Object problem,
Laurence Finston <=
- Re: Union Type Object problem, Hans Aberg, 2004/08/09
- Re: Union Type Object problem, Laurence Finston, 2004/08/09
- Message not available
- Re: Union Type Object problem, Hans Aberg, 2004/08/10
- Re: Union Type Object problem, Laurence Finston, 2004/08/10
- Message not available
- Re: Union Type Object problem, Hans Aberg, 2004/08/11
- Re: Union Type Object problem, Laurence Finston, 2004/08/12
- Re: Union Type Object problem, Hans Aberg, 2004/08/12
- Re: Union Type Object problem, Laurence Finston, 2004/08/12
- Re: Union Type Object problem, Frank Heckenbach, 2004/08/13
- Re: Union Type Object problem, Laurence Finston, 2004/08/13