gpt4 book ai didi

c++ - 如何在 C++ 中返回 unique_ptr 列表?

转载 作者:行者123 更新时间:2023-11-30 04:58:41 26 4
gpt4 key购买 nike

<分区>

这是我想从函数中获取 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();
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com