Understanding rvalue references

后端 未结 5 878
清歌不尽
清歌不尽 2020-12-15 19:03

I think there\'s something I\'m not quite understanding about rvalue references. Why does the following fail to compile (VS2012) with the error \'foo\' : cannot conver

5条回答
  •  时光取名叫无心
    2020-12-15 19:35

    It's the "no name rule". Inside bar, x has a name ... x. So it's now an lvalue. Passing something to a function as an rvalue reference doesn't make it an rvalue inside the function.

    If you don't see why it must be this way, ask yourself -- what is x after foo returns? (Remember, foo is free to move x.)

提交回复
热议问题