Will containing a `std::unique_ptr` make the default copy constructor a deleted function?

Viewed 53

The fact that unique_ptr doesn't allow copy which means no more than one object can share the same underlying data. If I contain an object of unique_ptr in my class will the compiler be wise enough to make the implicit copy constructor a deleted function?

class Blob {
    public:
        Blob(){}
    //  Blob(const Blob& rhs){}
        unique_ptr<int> upi{make_unique<int>(0)};
};

int main(int argc, char* argv[]) {

    Blob b;
    cout << *b.upi << endl;

    Blob b2(b); // error: Error C2280   'Blob::Blob(const Blob &)': attempting to reference a deleted function

}

If I un-comment the definition of the user-defined copy constructor then everything is alright as long as no copying of the unique_ptr there.

0 Answers
Related