N
Newsgroup - Ann
Hi:
I saw the following codes from the FAQ about the contiguous storage of
vector. I am just wondering how does the implementation of the <vector>
guarantee the contiguous? What if a vector v was defined first as a
5-element vector, and then was increased dramatically but the corresponding
contiguous area has already been occupied by other objects? Maybe sounds
stupid to you gurus, but it does confuse me Thanks.
----------------------
#include <vector>
#include "Foo.h" /* get class Foo */
// old-style code that wants an array
void f(Foo* array, unsigned numFoos);
void g()
{
std::vector<Foo> v;
...
f(&v[0], v.size()); ? safe
}
----------------------------
I saw the following codes from the FAQ about the contiguous storage of
vector. I am just wondering how does the implementation of the <vector>
guarantee the contiguous? What if a vector v was defined first as a
5-element vector, and then was increased dramatically but the corresponding
contiguous area has already been occupied by other objects? Maybe sounds
stupid to you gurus, but it does confuse me Thanks.
----------------------
#include <vector>
#include "Foo.h" /* get class Foo */
// old-style code that wants an array
void f(Foo* array, unsigned numFoos);
void g()
{
std::vector<Foo> v;
...
f(&v[0], v.size()); ? safe
}
----------------------------