Using of rvalue references in c++11

前端 未结 4 1084
渐次进展
渐次进展 2020-12-17 21:18

I would like to implement a function that fills up a vector and then returns an rvalue reference. I tired something like:

std::vector &&fi         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-17 21:47

    If you just remove the && from your function it should work, but it will not be a reference. fill_list() will create a vector and return it. During the return a new vector will be created. The first vector that was created inside fill_list() will be copied to the new vector and then will be destroyed. This is the copy constructor's work.

提交回复
热议问题