【发布时间】:2013-01-10 03:33:17
【问题描述】:
我已经搜索了几个小时来寻找解决方案,并尝试了不同的方法来解决与 unique_ptr 相关的编译错误,并且没有复制/没有分配。我什至写了一个隐藏的副本并赋值,以防止vector调用它无济于事。
这是导致编译错误的代码:
class World{
World(const World&) {}
World& operator=(const World&) {return *this; }
std::vector<std::vector<std::unique_ptr<Organism>>> cell_grid;
public:
World() {
cell_grid = std::vector<std::vector<std::unique_ptr<Organism>>> (20, std::vector<std::unique_ptr<Organism>> (20, nullptr));
}
~World() {}
};
编译错误与私有成员访问问题有关。
【问题讨论】:
标签: c++ vector c++11 unique-ptr