What's the point of g++ -Wreorder?

后端 未结 5 644
花落未央
花落未央 2020-11-29 17:49

The g++ -Wall option includes -Wreorder. What this option does is described below. It is not obvious to me why somebody would care (especially enough to turn this on by de

5条回答
  •  失恋的感觉
    2020-11-29 18:22

    Other answers have provided some good examples that justify the option for a warning. I thought I'd provide some historical context. The creator of C++, Bjarne Stroustrup, explains in his book The C++ programming language (3rd edition, Page 259):

    The members’ constructors are called before the body of the containing class’ own constructor is executed. The constructors are called in the order in which they are declared in the class rather than the order in which they appear in the initializer list. To avoid confusion, it is best to specify the initializers in declaration order. The member destructors are called in the reverse order of construction.

提交回复
热议问题