相关疑难解决方法(0)

应该何时编译生成移动构造函数?

我使用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;
};
Run Code Online (Sandbox Code Playgroud)

我希望这个类生成移动构造函数/赋值.事实是我没有一个琐碎的构造函数,因为我没有动作吗?还是有其他因素影响这个?

c++ visual-c++ move-semantics c++11 visual-studio-2012

14
推荐指数
1
解决办法
4753
查看次数