123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include <vector>
- #include <iostream>
- using namespace std;
- class A
- {
- int *data;
- public:
- A(): data(new int[100])
- {
- cout << "constructing A, data is " << data << endl;
- }
- A(A &&x):
- data(x.data)
- {
- cout << "moving A, data is " << data << endl;
- x.data = nullptr;
- }
- ~A()
- {
- if (data)
- delete [] data;
- }
- void set(int i, int x)
- {
- data[i] = x;
- }
- void print(int i)
- {
- cout << data[i] << endl;
- }
- };
- int main()
- {
- vector<A> va;
- va.emplace_back();
- va.emplace_back();
- va.emplace_back();
- va.emplace_back();
- va.emplace_back();
- va.emplace_back();
- }
|