请问这段代码为何这么写
template <class U>
RefPtr(const RefPtr<U> & other) : m_ptr(other.get()) {
if (T * ptr = m_ptr) {
ptr->addRef();
}
}
这段代码为什么不这样写:
template <class U>
RefPtr(const RefPtr<U> & other) : m_ptr(other.get()) {
if (m_ptr != 0) {
m_ptr->addRef();
}
}
第一种写法多了一个赋值操作,为什么要这么写呢?