当前位置:网站首页>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 .

边栏推荐
- Hash table and full comments
- 【软件测试】最全面试问题和回答,全文背熟不拿下offer算我输
- 电气工程及其自动化
- Digital scrolling increases effect
- NuScenes数据集关于Radar数据的统计
- The 8 element positioning methods of selenium that you have to know are simple and practical
- C language exercises_ one
- MySQL提升大量数据查询效率的优化神器
- INS/GPS组合导航类型简介
- Static proxy of proxy mode
猜你喜欢

LeetCode 77:组合

Redis入门完整教程:客户端案例分析

Huitong programming introductory course - 2A breakthrough

Redis入门完整教程:RDB持久化

Mmdetection3d loads millimeter wave radar data
Django database (SQLite) basic introductory tutorial

How to design interface test cases? Teach you a few tips to draft easily

慧通编程入门课程 - 2A闯关

Read fast RCNN in one article

测试优惠券要怎么写测试用例?
随机推荐
Redis入门完整教程:复制配置
MMDetection3D加载毫米波雷达数据
fasterxml ToStringSerializerBase报错
Leetcode:minimum_depth_of_binary_tree解决问题的方法
Go swagger use
Redis getting started complete tutorial: common exceptions on the client
Redis入门完整教程:客户端管理
代码调试core-踩内存
Redis introduction complete tutorial: client case analysis
Django database (SQLite) basic introductory tutorial
AWS learning notes (I)
Linear list --- circular linked list
What are the characteristics of the operation and maintenance management system
How to write test cases for test coupons?
Safety delivery engineer
电气工程及其自动化
CSDN 夏令营课程 项目分析
Convert widerperson dataset to Yolo format
Wireshark installation
Apifox,你的API接口文档卷成这样了吗?