ahodgson@athena.mit.edu (Antony Hodgson) (08/09/90)
Turbo Pascal offers the ability to declare one variable first, and then later to declare another variable of a perhaps different type which has the same address as the first. This is equivalent to declaring a union in C++ except that the two variables need not be declared at the same time. For my application, separating the points of declaration is essential. I want to reserve space for a void pointer in a base class, but reinterpret it as an appro- priately typed pointer in derived classes without having to explicitly cast the pointer every time I want to use it. The problem with simply declaring a new pointer of the appropriate type and setting it equal to the value of the void pointer is that the derived class then carries with it two pointers pointing at precisely the same thing. I had also considered using a preprocessor substitution in the derived class (i.e., #define DerivedPtr (type *) VoidPtr ), but then when I use a debugger, I'll have to explicitly cast VoidPtr anyway, which is inconvenient. Does anyone have any good solutions? Thanks in advance for your help. Tony Hodgson