当前位置:网站首页>第二十三课 临时对象
第二十三课 临时对象
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
边栏推荐
- User interface and im expression (IM 5.6)
- Nacos Foundation (6): Nacos configuration management model
- 远程访问家里的树莓派(上)
- 力扣-70.爬楼梯
- PCB的注意事项
- MySQL 的主从复制配置
- Fabric 1.0 source code analysis (33) implementation of peer channel command and subcommand
- oh-my-lotto
- Master slave replication configuration of MySQL
- IMEU如何与IMCU相关联(IM 5.5)
猜你喜欢

rebbitMQ的简单搭建

软银愿景基金进军Web3安全行业 领投CertiK 6000万美元新一轮投资

Redis learning 5 - high concurrency distributed lock practice

Relu function of activation function

Nacos Foundation (9): Nacos configuration management from single architecture to microservices

Nacos Basics (5): getting started with Nacos configuration

NativeForMySQL 连接MySQL8 提示:1251- Client does not support authentication protocol

初探 Lambda Powertools TypeScript

Resolution due to AMD not found_ ags_ x64. DLL, unable to continue code execution. Reinstallation of the program may solve this problem, Forza horizon 5

怎么进行固定资产盘点,资产盘点报告如何一键生成
随机推荐
项目实训-火爆辣椒
Database design of forum system
Application of remote integrated monitoring system in power distribution room in 10kV prefabricated cabin project
第四章 为IM 启用填充对象之强制填充In-Memory对象:教程(IM 4.7)
Yunna | fixed assets inventory supports multiple inventory methods (asset inventory)
Compress the curl library into a sending string of utf8 and send it with curl library
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
Database Navigator 使用默认MySQL连接提示:The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or repres
Siri gave the most embarrassing social death moment of the year
Exploring the equipment and teaching of robot education
魔域来了H5游戏详细图文架设教程
[web daily practice] eight color puzzle (float)
1.Electron开发环境搭建
配电房远程综合监控系统在10kV预制舱项目中的应用
简易投票系统数据库设计
论坛系统数据库设计
Here comes the detailed picture and text installation tutorial of H5 game
Share two practical shell scripts
QT 64 bit static version display gif
用户接口和IM表达式(IM 5.6)