Links in C ++ behave (almost) like hidden pointers. In particular, the same polymorphic behavior that you can get with a pointer, you can achieve it with a link. That is, the following (almost) equivalent
int *i = &a; int &j = a;
Assuming a is an integer defined somewhere in the previous lines. After the appearance of the link j, it is completely equivalent to the occurrences (* i). The main difference is that the link does not give you the pain of memory management, while the pointer does (you are responsible for handling the new (s) and deleted (s)). In addition, a pointer must not point to something, while a link cannot exist if it does not refer to anything. In addition, you can assume that they behave the same.
Therefore, it is absolutely legal to have a link to an abstract object. You will often find this in signature functions, where polymorphic behavior can be achieved either through references or pointers. But links give easier syntax, for example, the following code snippet shows
A a; A* ptr = &a; A& ref = a; ref(); ptr->operator()(); (*ptr)();
assuming class A overloads operator () .
bartgol
source share