[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Union Type Object problem
From: |
Hans Aberg |
Subject: |
Re: Union Type Object problem |
Date: |
Mon, 9 Aug 2004 19:29:18 +0200 |
At 17:23 +0200 2004/08/08, Laurence Finston 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()'.
The point is that dynamic_cast can in general only be resolved at compile
time. If you use void* in connection with polymorphy, then I think you may
decide on a fixed, static root class R, and then convert all polymorphy
types D to R first, and then converting R* to void*. When you convert back,
you must know from the static context which root class R it is. Once you
have gotten a R*, then you may apply a dynamic_cast<D*>(vp) if D is derived
from R. The result is a D* if vp is a pointer to a class derived from D,
otherwise 0 (modulo some protection stuff).
Hans Aberg
- 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, 2004/08/08
- Re: Union Type Object problem,
Hans Aberg <=
- 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
- Message not available
- Re: Union Type Object problem, Hans Aberg, 2004/08/12