help-bison
[Top][All Lists]
Advanced

[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: Sun, 8 Aug 2004 16:41:21 +0200

At 22:05 +0200 2004/08/07, Laurence Finston wrote:
>I haven't had a chance to test this, but nothing else leapt out at me as a
>probable cause for the error.
>
>> >   You could just use `void*' and cast the pointers to
>> >`Expression*' in the rules.  That's what I do.
>>
>> I think that one might loose polymorphy that way, or only preserve it in a
>> non-C++ standard way (it might not run on some C++ compilers).
>>
>
>If I cast a pointer to void to a base type with virtual functions, and the
>object pointed to is a derived type, a call to a member function on the object
> will resolve correctly.    I don't see how this loses polymorphism, nor how
>it could fail to compile.

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.

>I don't see anything wrong with your solution either, beyond what you mention
>yourself.  If the data members in the class were large, I might use pointers.
>I doubt that a semantic type containing five or six pointers would cause
>problems on typical systems today.

I suppose you mean my use of a class instead of a union: Clearly that
works, and the waste of memory is not so big, if the data types are small
(in fact, less than the use of location tracking). And in addition, there
is a need for me to sometimes use them in parallel, in which case I could
not use a union.

  Hans Aberg






reply via email to

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