When creating a constructor for some class, it has been advised to use an assignment list to initialize the member variables. This I think I understand, although not sure as to why this is so. Consider
1 2 3 4 5 6 7
class foo
{
foo() : m_var1(0), m_var2(0.0 {}
~foo();
int m_var1;
double m_var2;
} /* end foo() */
In this example we have variables of the class foo with a known time, int and double. Suppose we develop a class that is a template. How do we deal with initialization lists then? How should I address the list if the type can be string, or int, or char? Here is the same code with the template implemented.
1 2 3 4 5 6 7 8
template <typename T>
class foo
{
foo() : m_var1(0), m_var2(0.0) {} // how to address type string in assignment list?
~foo();
T m_var1;
T m_var2;
} /* end foo() */