//向基类构造函数传递实参p491 class Bulk_item : public Item_base{ public: Bulk_item(const std::string& book,double sales_price,std::size_t qty = 0,double disc_rate = 0.0): Item_base(book,sales_price),min_qty(qty),discount(disc_rate){} }; //在派生类构造函数中使用默认实参p491 class Bulk_item : public Item_base{ public: Bulk_item(const std::string& book,double sales_price = 0.0,std::size_t qty = 0,double disc_rate = 0.0): Item_base(book,sales_price),min_qty(qty),discount(disc_rate){} }; //定义Disc_item类p492 class Disc_item : public Item_base{ public: Disc_item(const std::string& book = "", double sales_price = 0.0, std::size_t qty = 0, double disc_rate = 0.0): Item_base(book, sales_price),quantity(qty), discount(disc_rate){} protected: std::size_t quantity; double discount; }; //重构 //重新实现Bulk_item以继承Disc_itemp493 class Bulk_item : public Disc_item{ public: Bulk_item(const std::string& book = "", double sales_price = 0.0,std::size_t qty = 0,double disc_rate = 0.0): Disc_item(book,sales_price,qty,disc_rate){}//不太懂 double net_price(std::size_t) const; };
时间: 2024-10-12 14:38:38