How do I pass a unique_ptr argument to a constructor or a function?

前端 未结 7 1766
挽巷
挽巷 2020-11-22 06:16

I\'m new to move semantics in C++11 and I don\'t know very well how to handle unique_ptr parameters in constructors or functions. Consider this class referenc

7条回答
  •  时光说笑
    2020-11-22 06:53

    Base(Base::UPtr n):next(std::move(n)) {}
    

    should be much better as

    Base(Base::UPtr&& n):next(std::forward(n)) {}
    

    and

    void setNext(Base::UPtr n)
    

    should be

    void setNext(Base::UPtr&& n)
    

    with same body.

    And ... what is evt in handle() ??

提交回复
热议问题