当前位置:网站首页>Left value, right value
Left value, right value
2022-07-07 02:51:00 【Qiange】
The left value 、 Right value
1. Basic concepts
(1)
The left value : You can take its address
Right value : You can't take its address
int main()
{
//int& a=10;// error : An lvalue reference cannot reference a constant , Lvalue reference is equivalent to :int* const( Constant pointer ),
const int& a=10;// correct
/* Equivalent to : int tmp=10; const int* const a=&tmp; */
}
(2)
int fun()
{
int a=10;
return a;
}
int main()
{
int x=fun();
//int& b=fun(); error
const int& c=fun();// correct
int&& d=fun();
return 0;
}
The analysis of the above code is as follows :
2. lvalue reference 、 Right quoting
(1)
lvalue reference : You need to reference a variable with a name , You cannot reference an unnamed object .
Right quoting : Only literal constants can be referenced , No name .
Because will die value is an unnamed object , So you can't use lvalue to reference , Can only be referenced with an R-value , And through the right value reference , It also increases the life cycle of the dying value .
3. Mobile build :
The heap memory is built once , If there is no mobile build , It will be built three times
notes : If there is a moving object, first mobilize the moving structure to frame the dead value object , Instead of calling ordinary copy constructs , If you don't move the structure , The normal copy construct will be called to construct the dead value object .
边栏推荐
- CSDN 夏令营课程 项目分析
- Code line breaking problem of untiy text box
- Leetcode:minimum_ depth_ of_ binary_ Tree solutions
- Classify the features of pictures with full connection +softmax
- Matlb| economic scheduling with energy storage, opportunity constraints and robust optimization
- AWS学习笔记(一)
- The so-called consumer Internet only matches and connects industry information, and does not change the industry itself
- 6-6漏洞利用-SSH安全防御
- Apifox, is your API interface document rolled up like this?
- Read fast RCNN in one article
猜你喜欢
随机推荐
wzoi 1~200
【2022国赛模拟】多边形——计算几何、二分答案、倍增
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
换个姿势做运维!GOPS 2022 · 深圳站精彩内容抢先看!
Dotconnect for DB2 Data Provider
widerperson数据集转化为YOLO格式
Niuke programming problem -- double pointer of 101 must be brushed
The so-called consumer Internet only matches and connects industry information, and does not change the industry itself
[leetcode]Search for a Range
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
[Mori city] random talk on GIS data (II)
Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
Have fun | latest progress of "spacecraft program" activities
Apifox, is your API interface document rolled up like this?
【Socket】①Socket技术概述
惯导标定国内外研究现状小结(删减版)
Cloud Mail . NET Edition
ERROR: Could not find a version that satisfies the requirement xxxxx (from versions: none)解决办法
Unity custom webgl packaging template
Apifox,你的API接口文档卷成这样了吗?