C++: Why don't I need to check if references are invalid/null?
- by jbu
Hi all,
Reading http://www.cprogramming.com/tutorial/references.html, it says:
In general, references should always
be valid because you must always
initialize a reference. This means
that barring some bizarre
circumstances (see below), you can be
certain that using a reference is just
like using a plain old non-reference
variable. You don't need to check to
make sure that a reference isn't
pointing to NULL, and you won't get
bitten by an uninitialized reference
that you forgot to allocate memory
for.
My question is how do I know that the object's memory hasn't been freed/deleted AFTER you've initialized the reference.
What it comes down to is that I can't take this advice on faith and I need a better explanation.
Can anyone shed some light?
Thanks,
jbu