<<< Reference examples | Index | Reference to a member >>> |
Given:
int i = 4; int x = 8; int& r = i;
Silly attempts to get r to refer to x instead of i:
r = x; // NO: now i == 8 int& r = x; // NO: variable redefinitions are illegal r = &x; // NO: type mismatch, r not a pointer-type r& = x; // NO: plain syntax error &r = &x; // NO: left operand must be l-value
Conclusion: r refers to i for r's entire life.
<<< Reference examples | Index | Reference to a member >>> |