C++11 emplace_back on vector?

前端 未结 8 603
借酒劲吻你
借酒劲吻你 2020-12-02 14:58

Consider the following program:

#include 
#include 

using namespace std;

struct T
{
    int a;
    double b;
    string c;
};

         


        
8条回答
  •  -上瘾入骨i
    2020-12-02 15:36

    You can create the struct T instance and then move it to the vector:

    V.push_back(std::move(T {42, 3.14, "foo"}));
    

提交回复
热议问题