This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: One way of viewing references is to consider that they have some similarities to C pointers, but with one level of pointer removed. Pointers are a frequent source of errors in C. A reference must be initialized, and its value (the pointed at object) cannot be changed after initialization. The value of the reference cannot change, but the value of the referenced object can, unless the reference is declared as const. So, for example: int i = 0; int& ir = i; ir = -19; // i gets the value -19 is acceptable, while: const int& irc = 47; irc = -37; // error is not. A constant reference that points at a value like 47 can be implemented using a temporary. References are useful in argument passing and return. Another use is illustrated below in the section on writing robust code....
View Full Document
- Fall '08