It is not immediately clear what you mean by "polymorphism with values." In C ++, when you have an object of type A , it always behaves like an object of type A This is quite normal and logical to expect. I do not see how this can behave differently. Thus, it is unclear what kind of “abilities” someone decided not to provide, which you are talking about.
Polymorphism in C ++ means one thing: calls to virtual functions made using an expression with a polymorphic type are resolved according to the dynamic type of this expression (in contrast to the static type for non-virtual functions). That is all that is needed.
Polymorphism in C ++ always works in accordance with the rule above. It works this way through pointers. This works through links. It works this way through immediate objects ("values", as you called them). So, it’s not entirely correct to say that polymorphism in C ++ only works with pointers and links. It also works with "values." They all follow the same rule as above.
However, for a direct object ("value"), its dynamic type always matches its static type. So, although polymorphism works for immediate meanings, it does not show anything truly “polymorphic”. The behavior of an immediate object with polymorphism is the same as without polymorphism. So, the polymorphism of an immediate object is a degenerate, trivial polymorphism. It exists only conceptually. This, again, is completely logical: an object of type A should behave like an object of type A How else can he behave?
To observe actual non-degenerate polymorphism, you need an expression whose static type differs from its dynamic type. Nontrivial polymorphism is observed when an expression of a static type A behaves (with respect to calls to virtual functions) as an object of a different type B For this, an expression of static type A must really refer to an object of type B This is only possible with pointers or links. The only way to make this difference between a static and a dynamic type of expression is to use pointers or references.
In other words, it is not true to say that polymorphism in C ++ only works through pointers or links. It’s right to say that with pointers or links, polymorphism becomes observable and non-trivial.
AnT
source share