Initialization order problem constructor initialization list

  Problems encountered today is the constructor initialization list of needs and order of the data members declared before they can be consistent, otherwise there will be an unexpected warning or error. Here is the code encountered the problem:

  

 1 //Quote.h
 2 #ifndef QUOTE_H
 3 #define QUOTE_H
 4 
 5 #include <string>
 6 
 7 class Quote
 8 {
 9     public:
10         Quote() = default;
11         Quote(const std::string& book, double sales_price) :
12             //price(sales_price), bookNo(book)  {  }
13             bookNo(book), price(sales_price)   {  }
14 
15         const:: STD String & ISBN () const { return bookNo;}
 16          Virtual  Double net_price (n-STD :: size_t) const { return n-*. price;} // virtual function, subclasses implement 
. 17          Virtual ~ Stock- ET Net () = default ; // destructors dynamic binding 
18 is      protected :
 . 19          Double . price = 0.0 ; // normal state where no discount price 
20 is      Private :
 21 is          STD :: String bookNo; // book ISBN number 
22 is  
23 is };
24 
25 #endif // QUOTE_H

  If the initialization list is initialized in accordance with the kind of the order of 13 rows, then there will be the following warning:

 

 So the simplest way is to sort the list according to a statement initialization sequence within a class data members. Further, the data list of the members of the derived class to initialize the base class should be initialized in front of the derived class.

Guess you like

Origin www.cnblogs.com/CushGuo/p/11867759.html