Alf P. Steinbach wrote:
* Jim Langston:
>"??" <le**********@gmail.comwrote in message
news:11**********************@i13g2000prf.googleg roups.com...
>>Name two cases where you MUST use initialization list as opposed to
assignment in constructors.
References and Base Classes are two.
Language level technical reasons:
1. Base classes.
2. Member variables with user-defined constructors.
3. Member variables with inaccessible or inappropriate assignment operator.
4. "const" member variables.
5. Reference members.
Other technical reasons:
6. When there are dependencies between member variables so that
some must be initialized before one where 1...5 applies.
Non-technical reasons:
7. When the coding guideline or other authority says so.
Number 8 is a "meta" reason for meta programming.
8. When initializing an member of a template class that you cannot
determine what type it will be because not doing so will result in
potential problems either with uninitialized POD's.
i.e.
template <typename Tstruct X
{
T v;
X() : v() {}
};
X<inti; // i.v is initialized to zero
X<std::strings; // s.v is initialized to ""
I suppose it's not really a MUST ...