Topic: Class declaration/definition consistency
Author: gyro@kestrel.edu (Scott Layson Burson)
Date: 24 May 91 17:24:04 GMT Raw View
In article <May.17.17.47.20.1991.1598@morley.rutgers.edu> 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
Author: rae@alias.com (Reid Ellis)
Date: 25 May 91 18:02:59 GMT Raw View
Mark Purtill <purtill@morley.rutgers.edu> writes:
|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.
Scott Layson Burson <gyro@kestrel.edu> writes:
|I think this is an excellent idea.
Note that if you change the inheritance hierarchy for a class, you now
have to go all over the place and change it wherever the class is
*declared*, as opposed to the one place where it is defined. It would
make changing the hierarchy of class inheritance on the same order as
that of changing the class interface.
One might point out that changing the inheritance of a class might in
fact change the interface however.
But I would still argue that this should not be "required" but,
rather, "optional" so as to prevent breaking all existing code that
simply declares a class.
Personally, when I declare a class, I use the "extern" keyword to make
it obvious what it is that I am saying. e.g.:
extern class A;
extern class B;
Reid
--
Reid Ellis
rae@utcs.toronto.edu || rae@alias.com
CDA0610@applelink.apple.com || +1 416 362 9181 [work]