When to Use Pointers vs References
Pick between pointers and references based on optionality and ownership semantics.
Different Tools for Different Jobs
References and pointers both let you indirect to another object — but with different semantics. Use each where it shines.
References for Mandatory Targets
A reference cannot be null and cannot be reseated. Use a reference parameter when the function always needs a real object.
void render(const Image& img); // must have an imageAll lessons in this course
- Raw Pointers and the Address-of Operator
- Dereferencing and Pointer Arithmetic
- nullptr and Null Pointer Safety
- When to Use Pointers vs References