在Qt文档中,我们看到:
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.这两种功能有什么区别?这很清楚什么是引用空指针,但是这里的意思是什么?
“如果对象为空”?
如何确定QSharedPointer 是否为空?这些函数如何与QSharedPointer::data() != null相对应?
发布于 2013-11-12 10:49:29
来自QSharedPointer类的Qt源:
inline bool operator !() const { return isNull(); }这证实了@JoachimPileborg在他的评论中所说的- isNull()函数和operator!()是等价的。
发布于 2013-11-12 09:51:18
“空”QSharedPointer包装T* t,其中t= 0/NULL/nullptr。这就是"object is null“的意思
isNull()和operator!()是等价的,您可以使用任何一个。
默认情况下,共享指针为空,或者当显式设置为0/nullptr时:
QSharedPointer<T> t; //null
QSharedPointer<T> t2(new T); //not null
QSharedPointer<T> t3(0); //null
QSharedPointer<T> t4(nullptr); //null
t2.clear(); //not null before, now nullhttps://stackoverflow.com/questions/19925693
复制相似问题