jeudi 19 décembre 2019

how to "push back" an non-copyable object into a vector [duplicate]

This question already has an answer here:

I tried to use push_back and emplace_back, but all failed.

class Base30 {
public:
    Base30() = delete;
    Base30(int a, int b) : a(a), b(b) {}
    Base30(const Base30& other) = delete;

    int a;
    int b;
};

int main()
{
    vector<Base30> vec;

    Base30 b1 = { 1, 2 };

    //vec.push_back(b1);  // fail

    //vec.emplace_back(1, 2);  // fail

    return 0;
}

How to push_back Base30 into this vector?

Aucun commentaire:

Enregistrer un commentaire