I have this code, but it is not a practical example.
Ex.
class Animal
{
int i;
int& ref;
public:
Animal() : ref(i)
{
}
};
Can anyone provide a real life example where ref is required as a class member so that I can understand it better?
Any time that multiple objects of some class A all need to refer to a single shared instance of the same or some other class; for example, several
Peoplecan all have the same mother and/or father: