How does returning std::make_unique work?

后端 未结 5 2272
旧巷少年郎
旧巷少年郎 2021-02-19 16:05

I have a base class and its subclass:

class Base {
    public:
    virtual void hi() {
        cout << \"hi\" << endl;
    } 
};

class Derived : pub         


        
5条回答
  •  忘了有多久
    2021-02-19 16:58

    In the above listed example, (1) returns an rvalue but (2) is not an rvalue and is attempting a copy on the unique_ptr, which you cannot do for a unique_ptr.

    Using move works because you are treating the unique_ptr at that point as an rvalue.

提交回复
热议问题