<分区>
这是我想从函数中获取 unique_ptr 列表的代码片段。尽管我已经向这个结构添加了复制/移动构造函数,vs 编译器仍然报告了 c2280 错误(试图引用已删除的函数)。有人知道发生了什么吗>?
#include<iostream>
#include<memory>
#include <list>
using namespace std;
struct info {
info() {
cout << "c" << endl;
}
~info() {}
info(const info&w) {
cout << "cc" << endl;
}
info(const info&&w) {
cout << "ccc" << endl;
}
info& operator==(const info&) {
cout << "=" << endl;
}
info& operator==(const info&&) {
cout << "==" << endl;
}
};
typedef unique_ptr<info> infop;
list<infop> test() {
list<infop> infopList;
info t,t1;
infop w = make_unique<info>(t);
infop w1 = make_unique<info>(t1);
infopList.push_back(w);
infopList.push_back(w1);
return infopList;
}
void main() {
list<infop> pl = test();
}