Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!sics.se!sics!tomas From: tomas@inmic.se (Tomas Lundstrom) Newsgroups: comp.lang.c++ Subject: type casting Message-ID: Date: 6 Feb 91 09:39:18 GMT Sender: news@sics.se Distribution: comp Organization: Swedish Institute of Microelectronics, Kista Lines: 59 Hello, I'm not sure that my first posting made it, so I try again (sorry if it is a duplicate). Suppose I have a class hierarchy A / \ / \ B C / \ / \ D E The descendants have no additional data, only additional functions. What I want is a 'universal object' that can be used for objects of all classes in the tree. The question is: Can I use an 'A' object and just cast it to the descendant classes ? It works on our system, but I suspect it might be implementation dependent. (In other words, is it guaranteed that the layout of an A object and an E object is identical, if C and E only adds functions to A ?) If the answer to these questions is 'no', I was thinking of creating a "universal" class A' like this: A / \ / \ B C | / \ | / \ | D E | | / | | / | | / \ | / A' I guess that an A' object always could be safely cast to any other class in the tree. I also suspect that this is not what multiple inheritance was intended for ... will I be condemned as a heretic ? ;-) I'd appreciate constructive comments, thanks /Tomas -------------_----------------------------------------------------------------- Tomas Lundstrom NMP-CAD /^^^\_/^^^^> Swedish Institute of Microelectronics / (_____________ # # # P.O. Box 1084 | II | | _______________||||||| S-164 21 Kista \ o o ( # # # Tel. +46-8-7521126 \___/^\__> email tomas@nmpcad.se Rockus et rollare necesse est -------------------------------------------------------------------------------