c++ - Why does referencing an unique_ptr behave this way? -


vector<int> v1, v2;  /*1*/        vector<int> &somereference=v1;     //compiles /*2*/        somereference=v2;         //compiles  vector<unique_ptr<int>> vec1, vec2;  /*3*/        vector<unique_ptr<int>> &otherreference=vec1;    //compiles /*4*/        otherreference=vec2;     //error 

i understand if neither line 3 nor 4 didn't compile, third 1 doesn't cause compilation errors - apparently there no problems initializing reference first time , passing around; problem appears when try assign second time.

i can't understand going on behind scenes makes second assignment impossible.

this has nothing references, it's unique_ptr cannot copied.

unique_ptr<int> p1, p2; p1 = p2; // error 

consequently, vectors of unique_ptr cannot copied either.

vector<unique_ptr<int>> vec1, vec2; vec1 = vec2; // error 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

node.js - Node - Passport Auth - Authed Post Route hangs on form submission -

Does Firefox offer AppleScript support to get URL of windows? -