On May 9, 8:11 am, red floyd <no.s...@here.dudewrote:
Jess wrote:
Hello,
Is it possible to put object references into a container, such as a
vector? I tried the following, but the compiler gave me lots of error
messages.
No. Container elements must be assignable (and/or copyable?).
Once a reference has been initialized, it cannot be made to reference
any other object (unlike some other programming languages). In other
words, in the lifetime of a reference, it can reference one and only
one object.
Since the element of a container is normally constructed before an
object "is put in the container element", it is no longer possible to
store the object in the reference since the reference has already been
created and initialized. If it were possible to change the object
that a reference references, we would not have this problem. Since
pointers are allowed to point to different objects in their lifetime,
we must use pointers instead.
Are my statements above basically correct (sorry for the English
syntax, I did not start leaning English until I was 4 years old :) )?
Bob