当前位置:网站首页>Qt智能指针易错点
Qt智能指针易错点
2022-07-25 23:43:00 【StephenQin】
- Qt中智能指针间进行动态转换的方法是qSharedPointerDynamicCast,使用该方法不会增加引用计数。
- 将this指针转化为智能指针时,不能够使用QSharedPointer(this)这种方式,而要采用sharedFromThis()这类的方法.
- 构造和类型转换放在一起容易出错:
非智能指针的代码:
Base *p = new Derived();
智能指针的错误转化写法:
//错误写法1
QSharedPointer<Base> p(new Derived);
//错误写法2
QSharedPointer<Base> p = QSharedPointer<Base>(new Derived);
//正确写法:
QSharedPointer<Base> p = QSharedPointer<Derived>(new Derived);
//要保证构造的时候类型一致,类型转换的工作交给”=”.
边栏推荐
- What is a physical firewall? What's the effect?
- Matchmaker's words
- Strategy mode_
- Node Foundation
- Anti shake and throttling
- [nodejs] nodejs create a simple server
- Interview focus - TCP protocol of transport layer
- TS function
- Redis basic data type (string/list/set/hash/zset)
- Loading process such as reflection
猜你喜欢

Learning exploration - waves

numeric学习之iota,accumulate

Redis basic data type (string/list/set/hash/zset)

R language installation tutorial | graphic introduction is super detailed

Read the field status of account in ABAP code (hidden, optional, required)

Npm+ module loading mechanism

S4/HANA ME21N创建PO 输出控制消息按钮丢失解决方法(切换EDI 输出模式BRF+至NAST模式)

Ratio of learning_ add,ratio_ subtract,ratio_ multiply,ratio_ Use of divide

What is the difference between'1 and'b1 when assigning values

@Import
随机推荐
Reduce method of array
initializer_ List tool library learning
Learning exploration - waves
Moment.js
The late Apple co-founder Steve Jobs was posthumously awarded the U.S. presidential medal of freedom
Imitating the magnifying glass effect of JD products -- JS Foundation
firewall 命令简单操作
[JUC] concurrent keyword volatile
numeric学习之iota,accumulate
Query commodity cases (operate data with array addition method) / key points
Taobao flexible.js file realizes flexible layout
Recursion of function (use recursion to find the factorial of 1-N) (use recursion to find Fibonacci sequence) (use recursion to traverse data)
TS union type
1913. 两个数对之间的最大乘积差-无需排序法
R语言安装教程 | 图文介绍超详细
三板斧!助你成为优秀软件工程师
图的遍历-DFS,BFS(代码详解)
Function definition and call
SAP Message No. VG202 IDoc E1EDK18 中付款条款已经转移:检查数据
Pytorch data input format requirements and conversion