"mlimber" <mlim...@gmail.com> wrote in news:1173294762.235842.253370
@j27g2000cwj.googlegroups.com:
On Mar 7, 1:59 pm, Andre Kostur <nntps...@kostur.net> wrote:
"mlimber" <mlim...@gmail.com> wrote in news:1173289964.171996.249820@
30g2000cwc.googlegroups.com:
On Mar 7, 12:28 pm, "ragged_hippy" <pranes...@gmail.com> wrote:
I wanted to create a vector of const references. Something like this:
vector<const x&> y;
where x is a class name.
Is this a valid statement? Will this work if I use a reference of 'y'
somewhere else?
Did you try it? Any compiler will instantly tell you whether pointers
to references are allowed. (Hint: they're not, but vector requires
pointers to its containees.)
Since when? Vectors contain copies of their contained objects, not
pointers to them.
But vectors dynamically allocate the contained objects, which in turn
requires a pointer to the value type.
Probably not. As least not individually. It requires a pointer to some
memory. IIRC, TR1 specifies that it even must be contiguous memory.
Whether that actually is a pointer to type (or to array of type), or merely
a void *, that's an implementation detail. What's probably happening
behind the scenes is that the vector allocates "sizeof(type) * capacity"
bytes of memory, and uses placement new in each position that holds a valid
object.
From a vector user's point of view, all that is required is that the type
contained in the vector is copy constructable and assignable (and that the
constructed/assigned to object is the same as the original, which is why
auto_ptr can't be stored in STL containers). There are no pointers
anywhere in sight.
suggested.