简体   繁体   中英

how does the default assignment operator implemented in actual stl

suppose we are implementing a vector class and we do

vector v;

v={1,2,3,4};

so,here we are implementing our own vector class so,how this list pass to assignment operator as an argument how we handle it because we passing constant which are not accessible by pointer variable and reference variable. But all this can be done in stl vector class, so how did they do?

Prior to C++17, all arguments to all functions name fully constructed objects.

A prvalue std::initialiser_list<int> object (with no name) is constructed from {1,2,3,4} , and that is the constructor's argument. That temporary object ceases to exist once v 's constructor ends (specifically at the end of the full expression that creates it).

From C++17 onward, a value that will initialise an object can be passed around. We still call it a prvalue std::initialiser_list<int> , but it isn't an object (yet). Somewhere in v 's initialisation, where it gets used, a std::initialiser_list<int> object is constructed. It also ceases to exist after the constructor is done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM