mercredi 30 mai 2018

How to erase a vector containing structs with std:unique_ptr?

The next source code does not even compile unless the clear() vector line is commented. Is anyone able to explain me why and how to fix it?

#include <vector>

class Class
{
public:
    typedef std::unique_ptr<int> Variable;

public:
    Class() {}
    Class(Class&& other) { variables = std::move(other.variables); }

private:
    std::vector<Variable> variables;
};

void main()
{
    std::vector<Class> container;
    container.push_back(Class());
    container.clear();
}

Aucun commentaire:

Enregistrer un commentaire