左值和右值
来源:互联网 发布:佛山采集器软件 编辑:程序博客网 时间:2024/04/30 01:03
C++ introduces a new mechanism called "rvalue reference" which, among other things, allows us to detect rvalue arguments via function overloading. All we have to do is write a constructor with an rvalue reference parameter. Inside that constructor we can do anything we want with the source, as long as we leave it in some valid state:
string(string&& that) // string&& is an rvalue reference to a string { data = that.data; that.data = 0; }
What have we done here? Instead of deeply copying the heap data, we have just copied the pointer and then set the original pointer to null. In effect, we have "stolen" the data that originally belonged to the source string. Again, the key insight is that under no circumstance could the client detect that the source had been modified. Since we don't really do a copy here, we call this constructor a "move constructor". Its job is to move resources from one object to another instead of copying them.
void stove(double && r3)
stove(double && r3) 直接把 r3的引用据为己有,并且原有的r3的引用失效
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- 左值和右值
- C++中的左值和右值
- 左值和右值的概念
- java合并图片
- 走迷宫
- ContentProvider的感想
- Uva1225 求数字0-9在前n个正整数中出现的次数(1<=n<=10000)
- 腾讯第三方登陆OAuth验证 数据入库
- 左值和右值
- android自定义时间控件NumberPicker
- LintCode-最小差
- 服务器端口映射
- 杭电oj-1018
- 【进程管理】进程(线程)创建
- 《剑指Offer》学习笔记--面试题45:圆圈中最后剩下的数字
- LintCode-最多有k个不同字符的最长子字符串
- 【小白话通信】连续分布之间的关系