G
Guest
This question kind of follows on from Mike Spass’ posting 10/11/2004; I don’t
understand why you can’t declare an implicit operator to convert a base class
to a derived class.
The text books say “neither the source nor the target types of a conversion
can be a base type of the other, since a conversion would then already
existâ€. But this is not really true, whilst automatic (implicit) conversions
do occur from the derived class to the base class, they do not go the other
way because there is no way of knowing what items are in the derived class
that are not inherited from the base.
Each time I look at this I keep coming back to the same question: why can’t
I write an operator that states what to do with the other items?
understand why you can’t declare an implicit operator to convert a base class
to a derived class.
The text books say “neither the source nor the target types of a conversion
can be a base type of the other, since a conversion would then already
existâ€. But this is not really true, whilst automatic (implicit) conversions
do occur from the derived class to the base class, they do not go the other
way because there is no way of knowing what items are in the derived class
that are not inherited from the base.
Each time I look at this I keep coming back to the same question: why can’t
I write an operator that states what to do with the other items?