#include
#include
using std::vector;
int main(void) {
vector A, B;
vector *C;
A.resize(1000);
printf("%d %d\n", A.size(), A.capacity());
A.clear();
printf("%d %d\n", A.size(), A.capacity());
A = B;
printf("%d %d\n", A.size(), A.capacity());
A.swap(B);
printf("%d %d\n", A.size(), A.capacity());
C = new vector;
C->resize(1000);
printf("%d %d\n", C->size(), C->capacity());
delete C;
C = new vector;
printf("%d %d\n", C->size(), C->capacity());
return 0;
}
The second method (new and delete) I'm not 100% sure it works, cuz in my case, the elements are pointers, so I adopt the first method which works.
沒有留言:
張貼留言