DJ_AM_Juicebox
asked on
copying a vector
Hi,
I wrote the following:
typedef vector<vector<unsigned short> > Whatever;
Whatever w1;
Whatever w2;
w1.resize(100);
for (int i = 0; i < 100; i++) {
w1[i].resize(5);
for (int j = 0; j < 5; j++) {
w1[i][j] = j;
}
}
// Does this do a one for one copy so that w2 is equivalent to w1?
w2 = w1;
Thanks
I wrote the following:
typedef vector<vector<unsigned short> > Whatever;
Whatever w1;
Whatever w2;
w1.resize(100);
for (int i = 0; i < 100; i++) {
w1[i].resize(5);
for (int j = 0; j < 5; j++) {
w1[i][j] = j;
}
}
// Does this do a one for one copy so that w2 is equivalent to w1?
w2 = w1;
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No, STL and its design is cool ;o)
The principlec/conventions are to invoke the appropriate operators for the contained types, thus leading to an elegant result in both use and design for the people that follow them.
The principlec/conventions are to invoke the appropriate operators for the contained types, thus leading to an elegant result in both use and design for the people that follow them.
You also could do:
typedef std::vector<std::vector<un signed short> > Whatever;
unsigned short a[5] = { 0, 1, 2, 3, 4, };
Whatever w1(100, vector<unsigned short>(&a[0], &a[5]));
to get the same as above with your loop.
Regards, Alex
typedef std::vector<std::vector<un
unsigned short a[5] = { 0, 1, 2, 3, 4, };
Whatever w1(100, vector<unsigned short>(&a[0], &a[5]));
to get the same as above with your loop.
Regards, Alex
ASKER