posted 23 years ago
Hi Willie,
Let's go through the options:
1. o1 is a reference of type Object, o2 is a reference of type IFace pointing to an object of class CFace. Since CFace is implicitely an object the assignment is valid.
2. b is a reference of type Base, ob is a reference of type ObRef pointing to an object of class ObRef. Since ObRef is a subclass of Base the conversion in the assignment is allowed and thus the assignement is calid.
3. b and ob the same as in 2, but this time we try to have a conversion of b to ob, this is not valid since b (of class Base) is a superclass of ob (of class ObRef), thus a explicit cast is needed here otherwise there will be a compilation error.
4. o1 is a reference of type Object, b a reference of type Base pointing to an object of class Base, since Base is_a Object (i.e. Base is a subclass of Object) the assignment is valid.
Keep in mind the following
if you are trying to convert an object in an assignment like this
Oldtype o;
Newtype n = o;
then Oldtype must be a subclass of Newtype OR in the case Newtype is an interface, Oldtype must implement the interface Newtype.
Hopes that helps, let me know if something is wrong or unclear
Val