C++ nullptr 的一种实现

C/C++ 程序员都应该了解NULL, 0, nullptr,  NULL表示空指针,即指针不指向任何对象,C++11后有多了nullptr更好是表了这类概念,看看nullptr是如何实现的:

 

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 = {};

posted @ 2016-03-18 12:30  KEO's  阅读(1223)  评论(0编辑  收藏  举报