COM221 5 C++ References
COM221 5 C++ References
• Returning a reference to an
object on the heap
• Must be avoided
References
• References versus pointers
• References are cleaner and easier to use.
• Prefer references over pointers wherever
possible
• References cannot be reassigned
• Thus, use pointers of you need to reference
one object and then another
• References cannot be null
• Use a pointer if there is a chance an object
will be null.
• Be careful NOT to reference out of scope
objects.