How to declare a vector of unique_ptr's as class data member?

后端 未结 5 1324
借酒劲吻你
借酒劲吻你 2021-02-20 11:26

I\'d like to have a vector of unique_ptr\'s as a member of a class I\'m making.

class Foo {
    [...]

private:
    vector> barList;
         


        
5条回答
  •  野的像风
    2021-02-20 12:09

    The problem here is that somewhere, your code is attempting to call the "copy-assignment" operator of Foo.

    This causes the compiler to attempt to generate a copy-assignment operator which calls the copy-assignment operators of all the subobjects of Foo. Eventually, this leads to an attempt to copy a unique_ptr, an operation which is not possible.

提交回复
热议问题