From Walt Karas · 1996-03-29 03:17 · #73502 in EMULATE
DN>Well, certainly you sometimes need to down-cast. But that does not mean it DN>is not low, demeaning, kludgy and so forth. In fact, good C++ style would DN>tend towards avoiding it where it can be avoided, and then using RTTI todo DN>it 'safely' where it cannot. It seems to me your opinions are base on pure aesthetics. I agree that aesthetics are important in software design and implementation, but they need to be tied to practical considerations. Polymorphism is not possible in C++ without casting, and polymorphism is the most important aspect of O-O Programming. Explicit casting is often necessary, and sometimes desirable for improved code readability. The only nasty thing about casting is that it is legal to cast any pointer type to any other pointer type, e.g.: A a; B *b = (B *) &a; I think you should be required to cast to (void *) first: A a; B *b = (B *) (void *) &a; This clearly flags the cast as being potentially non-portable. I don't know what RTTI is. Is it part of the language standard, or some implementation? The nice thing about casting a class instance to a base or derived class instance is that it only involves adding an offset to the address of the instance. If such considerations seem crude, the rational response is probably to program in SmallTalk instead of C++. --- þ SLMR 2.1a þ --- Simplex BBS (v1.07.00Beta [DOS]) * Origin: To hell with the prime directive, FIRE! (1:151/117)