Re: Effective C++ by Scott Meyers
* Peter:
"Salt_Peter" <pj_hern@yahoo.com> wrote in message
news:1172283519.695620.58270@z35g2000cwz.googlegroups.com...
On Feb 23, 6:10 pm, "Peter" <pet...@xpedion.com> wrote:
Peter wrote:
I was thinking that this rule is already in broad usage and should be
part of any modern book on C++.
and on page 138 he made a mistake in the order of constructor calls.
The correct order is:
bm1::constructor()
bm2::constructor()
Base::Base()
dm1::constructor()
dm2::constructor()
dm3::constructor()
Derived::Derived()
I left out the order of destructor calls in case of an exception.
But this is simple, as it is in reverse order.
This mistake did more damage than the book did good.
It is not in reverse order. In the sequence above Derived() is invoked
the destruction is in reverse order of the constructors.
Only these destructors are called, for which the constructor was
successful.
This is also true in case of the destruction is caused by an exception
thrown.
Do you claim that it is not so?
Peter is talking about constructor calls, you're talking about finished
initializations (constructor body executions).
Those are different things.
For example, if Base and Derived are coded like
void say( char const s[] ) { std::cout << s << std::endl; }
int theAnswer( char const s[] ) { say( s ); return 42; }
struct Base
{
Base( int ) { say( "Base constructor" ); }
};
struct Derived
{
Derived(): Base( theAnswer( "Derived init list" ) )
{ say( "Derived constructor" ); }
};
int main() { Derived(); }
But this does not matter -- I'm quite certain that I'm correct here.
I tested this in countless examples.
Try the above.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?