C++ Member Initialization List -


please explain how use member initialization lists. have class declared in .h file , .cpp file this:

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(); }; 

i'm initializing m_size on object creation because of const. how should write constructor? should repeat : m_size(5), m_top(-1), or can omit step?

example::example( int size, int grow_by) { ... code here } 

or

example::example( int size, int grow_by) : m_size(5), m_top(-1) { ... code here } 

this initialization list :

example::example( int size, int grow_by) : m_size(5), m_top(-1) { ... code here } 

and should done in cpp file.

don't error when did in header in example?


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -