亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 請(qǐng)教C++類定義 [打印本頁(yè)]

作者: harvey_perfect    時(shí)間: 2014-10-14 10:58
標(biāo)題: 請(qǐng)教C++類定義
各位大俠,小弟對(duì)c++不太熟悉,最近在看一個(gè)demo,其中包括c++的類定義,如下。其中構(gòu)造函數(shù)“scoped_array() : m_ptr(NULL) {}
”后面的: m_ptr(NULL) 代表什么意思?麻煩各位大俠給予指點(diǎn)。
謝謝先:wink:

template<typename T>
class scoped_array{
public:
  typedef scoped_array<T> this_type;

  scoped_array() : m_ptr(NULL) {}
  scoped_array(T *ptr) : m_ptr(NULL) { reset(ptr); }
  explicit scoped_array(size_t n) : m_ptr(NULL) { reset(n); }
  ~scoped_array() { reset(); }

  T *get() const { return m_ptr; }
  operator T *() const { return m_ptr; }
  T *operator ->() const { return m_ptr; }
  T &operator *() const { return *m_ptr; }
  T &operator [](int index) const { return m_ptr[index]; }

  this_type &operator =(T *ptr) { reset(ptr); return *this; }

  void reset(T *ptr = NULL) { delete[] m_ptr; m_ptr = ptr; }
  void reset(size_t n) { reset(new T[n]); }
  T *release() { T *ptr = m_ptr; m_ptr = NULL; return ptr; }

private:
  T *m_ptr;

  // noncopyable
  scoped_array(const this_type &;
  this_type &operator =(const this_type &;
}
作者: hellioncu    時(shí)間: 2014-10-14 11:02
構(gòu)造函數(shù)初始化列表
作者: harvey_perfect    時(shí)間: 2014-10-14 11:33
回復(fù) 2# hellioncu
能否通俗一點(diǎn),還是不明白m_ptr(NULL)  和構(gòu)造函數(shù)的關(guān)系,或者m_ptr(NULL)  起到什么作用?
剛接c++。
非常感謝!


   
作者: hellioncu    時(shí)間: 2014-10-14 11:39
harvey_perfect 發(fā)表于 2014-10-14 11:33
回復(fù) 2# hellioncu
能否通俗一點(diǎn),還是不明白m_ptr(NULL)  和構(gòu)造函數(shù)的關(guān)系,或者m_ptr(NULL)  起到什么 ...


就是個(gè)賦值,具體你搜索下“構(gòu)造函數(shù)初始化列表”
作者: harvey_perfect    時(shí)間: 2014-10-14 14:26
回復(fù) 4# hellioncu
非常感謝!


   
作者: zsszss0000    時(shí)間: 2014-10-14 18:16
這個(gè)功能就是初始化功能
m_ptr(NULL)即用NULL初始化m_ptr




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2