C++ provides another way of initializing member variables that allows us to initialize member variables when they are created rather than afterwards. This is done through use of an initialization list.
Using an initialization list is very similar to doing implicit assignments.
Example without initialization list.
Using an initialization list is very similar to doing implicit assignments.
Example without initialization list.
class Something { private : int m_nValue; double m_dValue; int *m_pnValue; public : Something() { m_nValue = 0; m_dValue = 0.0; m_pnValue = 0; } };
Now let’s write the same code using an initialization list:
|
No comments:
Post a Comment