当前位置:网站首页>第二十三课 临时对象
第二十三课 临时对象
2022-04-23 11:55:00 【꧁༺夜༒雨༻꧂】
第二十三课 临时对象
文章目录
一、示例
class test{
private:
int i;
public:
test(int j)
{
i = j;
}
test()
{
test(0); // 这里产生了临时对象
}
void printfi(void)
{
printf("%d", i);
};
}
int main(char* argc, char** argv)
{
test t;
t.printfi();
return 0;
}
以上函数输出的值不为0,这是为什么呢?
构造函数是一个特殊函数,直接调用构造函数会产生一个临时对象,临时对象的声明周期只有一条语句的时间,临时对象的作用域旨在一条语句中。临时对象是C++中值得注意的灰色地带
上述现象产生的原因是因为引入了临时对象。
- 现代 C++ 编译器在不影响最终执行结果前提下,会尽力减少临时对象的产生
二、小结
-
直接俄调用构造函数将产生一个临时对象
-
临时对象是性能的瓶颈,也是bug的来源之一
-
现代C++编译器会尽力避开临时对象
避开的前提是不影响执行结果
-
实际工程开发过程中需要认为的避开临时对象
版权声明
本文为[꧁༺夜༒雨༻꧂]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_34355238/article/details/124310645
边栏推荐
- Blog post navigation (real-time update)
- Windows11 安装MySQL服务 提示:Install/Remove of the Service Denied
- Castle. Dynamic proxy implements transaction unit control
- qt5. 8. You want to use SQLite in the 64 bit static library, but the static library has no method to compile the supporting library
- 《通用数据保护条例》(GDPR)系列解读三:欧洲子公司如何向国内母公司回传数据?
- thinkphp 添加图片文字水印生成带二维码的推广海报
- Significance of actively participating in middle school robot competition
- 魔域来了H5游戏详细图文架设教程
- 第四章 为IM 启用填充对象之强制填充In-Memory对象:教程(IM 4.7)
- Design and practice of the smallest short website system in the whole network
猜你喜欢

WIN10 启动后花屏

How to count fixed assets and how to generate an asset count report with one click
![Study notes of C [8] SQL [1]](/img/b3/cb684f3ee14cc4e313be217320d5d6.png)
Study notes of C [8] SQL [1]

Laravel增加自定义助手函数

QT 64 bit static version display gif

Exploring the equipment and teaching of robot education

5-minute NLP: text to text transfer transformer (T5) unified text to text task model

1. Construction of electron development environment

RebbitMQ的初步了解

Tan Xiang, CEO of Kechuang · Pera software: the essence of zero trust is digital security. To B should also deeply study the user's mind
随机推荐
Win10 splash screen after startup
Force buckle - 1137 Nth teponacci number
Nacos Foundation (9): Nacos configuration management from single architecture to microservices
Understanding of MQ
How imeu is associated with imcu (IM 5.5)
力扣-70.爬楼梯
Nacos Foundation (6): Nacos configuration management model
科创人·派拉软件CEO谭翔:零信任本质是数字安全,To B也要深研用户心智
Tclerror: no display name and no $display environment variable
云呐|固定资产盘点中,支持多种盘点方式(资产清查盘点)
全网最细的短网址系统设计与实战
MQ在laravel中简单使用
The fourth chapter is about enabling and disabling the im column storage of table space for im enabled filling objects (IM 4.5)
Redis optimization series (II) redis master-slave principle and master-slave common configuration
Im architecture: CPU architecture: SIMD vector processing (im-2.3)
ES6学习笔记二
IM表达式如何工作(5.3)
Fabric 1.0 source code analysis (33) implementation of peer channel command and subcommand
使用连接组优化连接 (IM 6)
Redis学习之五---高并发分布式锁实战