【发布时间】:2011-05-29 22:10:39
【问题描述】:
我刚刚在 Qt 中找到了以下代码,我有点困惑这里发生了什么。
尤其是reinterpret_cast<T>(0) 做了什么?
template <class T>
inline T qobject_cast(const QObject *object)
{
// this will cause a compilation error if T is not const
register T ptr = static_cast<T>(object);
Q_UNUSED(ptr);
#if !defined(QT_NO_MEMBER_TEMPLATES) && !defined(QT_NO_QOBJECT_CHECK)
reinterpret_cast<T>(0)->qt_check_for_QOBJECT_macro(*reinterpret_cast<T>(const_cast<QObject *>(object)));
#endif
return static_cast<T>(const_cast<QObject *>(reinterpret_cast<T>(0)->staticMetaObject.cast(const_cast<QObject *>(object))));
}
有人愿意解释一下吗?
【问题讨论】:
标签: c++ qt casting reinterpret-cast static-cast