Xref: utzoo comp.lang.c++:13644 comp.std.c++:932 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!samsung!rex!ukma!wuarchive!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jarthur!petunia!kestrel.edu!gyro From: gyro@kestrel.edu (Scott Layson Burson) Newsgroups: comp.lang.c++,comp.std.c++ Subject: Class declaration/definition consistency Message-ID: <1991May24.172404.17625@kestrel.edu> Date: 24 May 91 17:24:04 GMT References: <519f23cc.19260@apollo.HP.COM> Organization: Kestrel Institute, Palo Alto, CA Lines: 33 In article purtill@morley.rutgers.edu (Mark Purtill) writes: >williams_j@apollo.HP.COM (Jim Williams) writes: > >>I would like to throw out some ideas for discussion. Hopefully these >>concepts have not already been discussed to death. > > >>--------------------------- Example 1 ------------------------------------------ > >>class A; > >>class B; > >>B* f(A* ap) {return (B*)ap;} > >>-------------------------------------------------------------------------------- > > >>The compiler accepts the above code with no problems. But how can the complier >>cast an A pointer to a B pointer? The compiler doesn't know anything (yet) >>about A or B. Is A derived from B? Is B derived from A? If B is virtually >>derived from A, the cast in f() is illegal, but the compiler, not knowing if >>B is virtually derived from A, signals no error. Does this make sense? > > Let's call things like "class A;" *class declarations* and the >actual "class A {...};" the *class definition*. > An easy way to solve this problem would be to require a class >declaration to list the bases classes of the class defined. I think this is an excellent idea. -- Scott Gyro@Reasoning.COM