This is not "constructor initialization", this is the default parameter. It allows the caller to provide fewer arguments than the function; undefined arguments will default.
Another way to do this:
template<class T> class Node { public: Node(Node<T>* next, T data) : m_next(next), m_data(data) {} Node(Node<T>* next) : m_next(next), m_data() {} Node(void) : m_next(NULL), m_data() {} Node<T>* m_next; T m_data; };
In the case where less than two arguments are allowed, but calls different constructors (which have almost the same behavior).
There are several advantages to using separate overloads:
- No copy constructor is required if the
data parameter is always omitted. - The default constructor is not required if the
data parameter is always specified.
source share