理解move
#include <initializer_list>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
struct B {
int v = 100;
~B() { v = 0; }
};
struct A {
A(B* p) { aa = p; }
B* aa = nullptr;
A(A&& obj) { aa = obj.aa; }
A(const A& obj) { aa = obj.aa; }
};
void f(vector<A>& a) {
deque<A> q;
B b;
A obj(&b);
q.push_back(obj);
a.push_back(std::move(q.front()));
q.pop_front();
}
int main() {
std::vector<A> a;
f(a);
cout << a.begin()->aa->v << endl;
}
本文来自博客园,作者:ijpq,转载请注明原文链接:https://www.cnblogs.com/ijpq/p/17662698.html