QSharedPointer :: isNull()和operator!()之间的区别 [英] Difference between QSharedPointer::isNull() and operator!()

查看:905
本文介绍了QSharedPointer :: isNull()和operator!()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Qt文档中我们读到:

in Qt docs we read:

bool QSharedPointer::operator! () const

Returns true if this object is null. 
This function is suitable for use in if-constructs, like:

 if (!sharedptr) { ... }

bool QSharedPointer::isNull () const
Returns true if this object is holding a reference to a null pointer.

这两个函数有什么区别?这很清楚是什么引用一个空指针,但是这里的意思

What is the difference between these two functions? This is clear what is reference to a null pointer, but what means here


如果对象为空?

"if the object is null" ?

是什么决定 QSharedPointer 是否为空 >?这些函数如何对应于 QSharedPointer :: data()!= null

What determines if QSharedPointer is null? How do these functions correspond to QSharedPointer::data() != null ?

推荐答案

QSharedPointer 类的Qt源:

inline bool operator !() const { return isNull(); }

这确认了@JoachimPileborg在他的评论中说 - isNull / code>函数和 operator!()是等价的。

This confirms what @JoachimPileborg said in his comment - isNull() function and operator!() are equivalent.

这篇关于QSharedPointer :: isNull()和operator!()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆