Name two cases where you MUST use initialization list as opposed to
assignment in constructors.
Think of what cannot be constructed without initialisation. What do
you initialise in the initialisation list? Base classes and members,
right? So, what would require a class to be placed in the initialiser
list? What would require a member to be placed there?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
>"??" <leomayleomay@g mail.comwrote in message
>news:118700975 6.560911.236380 @i13g2000prf.go oglegroups.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 ""
Comment