当前位置:网站首页>Lesson 23 temporary objects
Lesson 23 temporary objects
2022-04-23 12:05:00 【Night rain】
Lesson 23 Temporary objects
List of articles
One 、 Example
class test{
private:
int i;
public:
test(int j)
{
i = j;
}
test()
{
test(0); // Here a temporary object is generated
}
void printfi(void)
{
printf("%d", i);
};
}
int main(char* argc, char** argv)
{
test t;
t.printfi();
return 0;
}
The output value of the above function is not 0, Why is that ?
A constructor is a special function , Calling the constructor directly will produce a temporary object , The declaration cycle of a temporary object is only the time of one statement , The scope of a temporary object is intended to be in a statement . The temporary object is C++ Notable gray areas in
The reason for the above phenomenon is the introduction of temporary objects .
- modern C++ The compiler does not affect the final execution result , We will try our best to reduce the generation of temporary objects
Two 、 Summary
-
Calling the constructor directly will produce a temporary object
-
Temporary objects are the bottleneck of performance , It's also bug One of the sources of
-
modern C++ The compiler will try to avoid temporary objects
The premise of avoiding is that it does not affect the execution result
-
In the process of actual project development, it is necessary to avoid temporary objects
版权声明
本文为[Night rain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231155356085.html
边栏推荐
- 初探 Lambda Powertools TypeScript
- Docker MySQL master-slave backup
- ES6学习笔记二
- kettle复制记录到结果和从结果获取记录使用
- 一文详解头部位姿估计【收藏好文】
- worder字体网页字体对照表
- 2022 love analysis · panoramic report of industrial Internet manufacturers
- 第四章 为IM 启用填充对象之启用和禁用列(IM-4.3 第三部分)
- Here comes the detailed picture and text installation tutorial of H5 game
- Tclerror: no display name and no $display environment variable
猜你喜欢
SOFA Weekly | 年度优秀 Committer 、本周 Contributor、本周 QA
Interpreting the art created by robots
Database design of forum system
IDEA 代码格式化插件Save Actions
Sofa weekly | excellent Committee of the year, contributor of this week, QA of this week
PSCP basic usage
IFLYTEK's revenue in 2021 was 18.3 billion yuan: a year-on-year increase of 41% and a net profit of 1.556 billion yuan
编程辅助工具推荐:图片工具snipaste
c# 设置logo图标和快捷方式的图标
一文详解头部位姿估计【收藏好文】
随机推荐
用户接口和IM表达式(IM 5.6)
Interpreting the art created by robots
第四章 为物化视图启用和禁用IM列存储(IM 4.6)
一文详解头部位姿估计【收藏好文】
ES6学习笔记二
Next.js 静态数据生成以及服务端渲染的方式
5个免费音频素材网站,建议收藏
科创人·派拉软件CEO谭翔:零信任本质是数字安全,To B也要深研用户心智
1.Electron开发环境搭建
On lambda powertools typescript
Fabric 1.0 source code analysis (33) implementation of peer channel command and subcommand
C# F23.StringSimilarity库 字符串重复度、文本相似度、防抄袭
程序员如何用130行代码敲定核酸统计
Im architecture: CPU architecture: SIMD vector processing (im-2.3)
Idea code quality specification plug-in sonarlint
oh-my-lotto
编程辅助工具推荐:图片工具snipaste
IM表达式如何工作(5.3)
SOFA Weekly | 年度优秀 Committer 、本周 Contributor、本周 QA
在 VSCode 中调试 Jest 的测试用例,VSCode调试Jest测试用例报错basedir=$(dirname “$(echo “$0“ | sed -e ‘s,\\,/,g‘)“)解决