当前位置:网站首页>The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
2022-07-06 17:38:00 【Wzzzzzzx】
void foo() {
QVariant a = 10;
QVariant b = 20;
int c = add(a, b);
return c;
}
int add(const QVariant &a, const QVariant &b) {
int left = a.value<int>();
int right = b.value<int>();
return a + b;
}
Here's add function , Although it's ours foo It will be called internally , But if it's not a performance bottleneck , Better be right add Check the parameters of .
The reason is that the subsequent maintainers are not as clear about the internal implementation of the function as we are , Some wrong types may be passed in .
This involves a defensive programming problem , We are the function writers , Try to prevent others from introducing a wrong thing , And try to solve this wrong thing .
This is similar to the question whether the smart pointer can take out the raw pointer and pass it into the function as an argument . In some cases , If we have enough knowledge about the internal implementation of functions , Ensure that it does not release the resource indicated by the pointer , We can pass the bare pointer .
One is the writer's perspective , One is the perspective of the caller .
边栏推荐
- 远程代码执行渗透测试——B模块测试
- C # nanoframework lighting and key esp32
- C# WinForm中DataGridView单元格显示图片
- Flink parsing (V): state and state backend
- 【ASM】字节码操作 ClassWriter 类介绍与使用
- Total / statistics function of MySQL
- 05个人研发的产品及推广-数据同步工具
- Flink analysis (I): basic concept analysis
- How does wechat prevent withdrawal come true?
- Case: check the empty field [annotation + reflection + custom exception]
猜你喜欢

Flink parsing (III): memory management

信息与网络安全期末复习(完整版)

06个人研发的产品及推广-代码统计工具

C# WinForm中DataGridView单元格显示图片

轻量级计划服务工具研发与实践

yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本

BearPi-HM_ Nano development board "flower protector" case

Integrated development management platform

Kali2021 installation and basic configuration

Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
随机推荐
2021-03-22 "display login screen during recovery" can't be canceled. The appearance of lock screen interface leads to the solution that the remotely connected virtual machine can't work normally
JVM 垃圾回收器之Serial SerialOld ParNew
The problem of "syntax error" when uipath executes insert statement is solved
PySpark算子处理空间数据全解析(4): 先说说空间运算
[reverse primary] Unique
pip install pyodbc : ERROR: Command errored out with exit status 1
Grafana 9 is officially released, which is easier to use and more cool!
集成开发管理平台
Automatic operation and maintenance sharp weapon ansible Foundation
Solr appears write Lock, solrexception: could not get leader props in the log
【逆向初级】独树一帜
Xin'an Second Edition: Chapter 12 network security audit technology principle and application learning notes
自动化运维利器ansible基础
About selenium starting Chrome browser flash back
Flink 解析(二):反压机制解析
Interpretation of Flink source code (II): Interpretation of jobgraph source code
[introduction to MySQL] third, common data types in MySQL
Vscode replaces commas, or specific characters with newlines
List set data removal (list.sublist.clear)
MySQL error reporting solution