【发布时间】:2017-04-01 02:27:06
【问题描述】:
来自维基百科,如果我们的编译器不支持c++11,我们可以自己实现一个,如下所示:
const class nullptr_t
{
public:
template<class T>
inline operator T*() const
{ return 0; }
template<class C, class T>
inline operator T C::*() const
{ return 0; }
private:
void operator&() const;
} nullptr = {};
上面的代码我看不懂。
----------更新------
对不起,我没有表达清楚。
template<class T>
inline operator T*() const
{ return 0; }
template<class C, class T>
inline operator T C::*() const
{ return 0; }
以上代码,我不懂语法。 我以前从未见过这种模板形式。(如“operator T C::*()”)
【问题讨论】:
-
哪部分不明白?
-
代码定义了一个名为
nullptr的const变量nullptr_t。 2 个隐式转换运算符允许nullptr在任何可以使用指针的地方使用。
标签: c++ c++11 templates nullptr