【发布时间】:2014-04-14 22:37:22
【问题描述】:
因此,我正在阅读一本关于使用 SFML 和 C++11 进行游戏开发的书,其中用于创建场景树的代码行给我带来了一些麻烦,这在我看来是有点过头了。由于 find_if 算法中 unique_ptr 的复制构造函数隐式删除,编译器返回错误。
这是带有 find_if 调用的函数。 Ptr 是std::unique_ptr<SceneNode> 的类型定义。这是我目前唯一使用 find_if 的地方。
SceneNode::Ptr SceneNode::detachChild(const SceneNode& node) {
auto found = std::find_if(mChildren.begin(), mChildren.end(), [&] (Ptr p) -> bool { return p.get() == &node; });
assert(found != mChildren.end());
Ptr result = std::move(*found);
result->mParent = nullptr;
mChildren.erase(found);
return result;
}
返回的错误是在算法本身中提出的,具体来说是“调用 'Ptr' 的隐式删除的复制构造函数。”
Call to implicitly deleted copy constructor in LLVM 有一个相关问题,但在我的情况下,答案没有多大意义。
请注意,我正在使用最新的 Xcode 5 版本进行开发。
【问题讨论】:
标签: c++ xcode c++11 llvm unique-ptr