c++11 emplace 与 push 的区别 直接传入对象(type) 1 2 3 4 5 6 7 8 9 class data{ int a, b; public: data(int x, int y) : a(x), b(y){} }; data x(5, 2); queue<data> q1; q1.push(x); q1.emplace(x); 传入时构造函数 1 2 q1.push(data(5, 2)); q1.emplace(data(5, 2)); emplace 可以直接传入构造对象需要的元素, 然后自己调用其构造函数 1 q1.emplace(5, 2); 第三种方法更节省内存 注意 1 2 3 emplace_back(type) 对应 push_back(type) emplace_(i, type) 对应 insert(typy, i) emplace_front(type) 对应 push_front(type) 1 恰似你一低头的温柔,娇弱水莲花不胜寒风的娇羞, 我的心为你悸动不休。 --mingfuyan