QSharedPointer::isNull() 和运算符之间的区别!().
Difference between QSharedPointer::isNull() and operator!()
在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
?
来自QSharedPointer
类的Qt来源:
inline bool operator !() const { return isNull(); }
这证实了@JoachimPileborg在他的评论中所说的话——isNull()
功能和operator!()
是等价的。
"null" QSharedPointer 包装一个 T* t,其中 t 等于 0/NULL/nullptr。这就是"对象为空"的含义
isNull() 和运算符!() 是等效的,您可以使用其中任何一个。
默认情况下,共享指针为 null,或者显式设置为 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 null
相关文章:
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- int(c) 和 c-'0' 之间的区别。C++
- C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 在 const 函数中通过引用和指针返回之间的区别
- 我想知道长双倍和双倍之间的区别
- 这 4 个 lambda 表达式之间有什么区别?
- 结构体 S { int align; } 之间的区别;(struct 关键字后的名称)和 struct { int al
- (double) 和 double() 之间的区别
- & 和 * 之间的区别
- std::is_convertible 和 std::convertible_to 之间的区别(在实践中)?
- 析构函数和'delete'之间的区别
- 在 typedef 内部使用 const 关键字和在 typedef 外部使用 const 关键字之间有区别吗?
- 从预序遍历构造 bst 的 c++ 和 python 解决方案之间的区别
- vector.back() 和 vector[vector.size() - 1] 之间的区别?
- 空指针常量 (nullptr)、空指针值和空成员指针值之间有什么区别?
- 函数签名与调用的函数不匹配,常量字符[]和字符*之间的区别?
- OpenMP #pragma omp for v/s #pragma omp parallel for 之间的区别?
- S() 与 S{} 之间的区别?