我使用VS11并使用以下内容:
class ContextWrapper
{
public:
ContextWrapper()
{
} //it should be defaulted I *guess* in order to have automatic move constructor ?
// no support in VS11 for that now
Context* GetContext()
{
return this->context.get();
}
void SetContext(std::unique_ptr<Context> context)
{
this->context = std::move(context);
}
//ContextWrapper(ContextWrapper&& other): context(std::move(other.context))
//{
//} // I would like this to be generated by the compiler
private:
ContextWrapper(const ContextWrapper&);
ContextWrapper& operator= (const ContextWrapper&);
std::unique_ptr<Context> context;
};
我希望这个类有生成的移动构造函数/赋值运算符。我没有一个平凡的构造函数是不是导致我没有得到移动?还是有其他因素影响了这个问题?
unique_ptr
),已经可以防止生成复制特殊成员函数,因此没有必要手动防止它们。 - R. Martinho Fernandesstd::unique_ptr
或引用),编译器就不应该自动生成复制构造函数(和赋值)。实际上,VC也没有这样做。因此,编译器抱怨的唯一原因是如果您在周围代码中尝试复制ContextWrapper
。但即使在这种情况下添加私有复制构造函数也无济于事,因为您的类在周围代码中的使用已经出现问题。 - Christian Rau= delete
了复制成员函数,那么你将会得到移动成员函数。然而,VC++似乎还没有实现生成移动成员函数的功能。 - Xeo