mardi 1 décembre 2015

Doesn't `QPoint` support `std::unique_ptr`?

I want to store QPoint in an object, which should be released automatically.

#include <QCoreApplication>
#include <memory>
#include <QPoint>

using namespace std;
class MyWidget{
public:
    vector<std::unique_ptr<QPoint>> _points;
    void f(QPoint point){
        std::unique_ptr<QPoint> pos(new QPoint(point));
        _points.push_back(pos);
    }
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    MyWidget wid;
    wid.f(QPoint(0,0));

    return a.exec();
}

The error message is:

F:\Qt\Qt5.5.0\Tools\mingw492_32\i686-w64-mingw32\include\c++\ext\new_allocator.h:120: error: use of deleted function 'std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = QPoint; _Dp = std::default_delete]' { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } ^

Does it mean that I am not supposed to use unique_ptr to store QPoint?

Aucun commentaire:

Enregistrer un commentaire