請說明如何使用成員初始化列表。我在.h文件和這樣的.cpp文件中聲明了一個類:class Example{private: int m_top; const int m_size; ...public: Example ( int size, int grow_by = 1 ) : m_size(5), m_top(-1); ... ~Example();};m_size由于,我正在初始化對象創建const。我應該如何編寫構造函數?我應該重復執行: m_size(5), m_top(-1),還是可以省略此步驟?Example::Example( int size, int grow_by){... some code here}要么Example::Example( int size, int grow_by) : m_size(5), m_top(-1){... some code here}
C ++成員初始化列表
慕桂英4014372
2019-10-30 10:17:17