On Mar 7, 11:58 am, "Mike Wahler" <mkwah...@mkwahler.net> wrote:
"ragged_hippy" <pranes...@gmail.com> wrote in message
news:1173288516.621145.276900@s48g2000cws.googlegroups.com...
Hi,
I wanted to create a vector of const references.
Why?
Something like this:
vector<const x&> y;
where x is a class name.
Not valid.
Is this a valid statement?
No.
Will this work if I use a reference of 'y'
No.
Standard library containers store objects. References
are not objects. References are alternate names for
existing objects.
somewhere else?
No.
You can, however, store pointers in your vector, since
pointers are objects.
Perhaps if you describe what problem you're trying to
solve, we might be able to give advice.
-Mike
Okay....I am trying to not use extra memory if possible.
I have this list of objects as a private member of a container. And I
have a public method defined in this container, that will take a
reference to vector buffer as a parameter and fill it up with objects
that it contains. If the vector for buffer is a vector of the object,
then all objects will be copied into this buffer. So, I thought may be
a vector of references might be better. But yes I immediately got his
huge set of compiler errors which I didn't expect.
Does this make sense?
-PJ.
So just store them as a vector of pointers.