int main() { Quote q("aaa", 10.60); Bulk_quote bq("bbb", 111, 10, 0.3); Limit_quote lq("ccc", 222, 10, 0.3); /** @note Not dynamic binding! * The codes below are not dynamic binding. The compiler has known what the * r refering to at compile time. As a result, the virtual function debug of * the subobject is called. */ Quote *r = &q; r->debug(); std::cout << "\n"; r = &bq; r->debug(); std::cout << "\n"; r = &lq; r->debug(); std::cout << "\n"; std::cout << "====================\n"; q.debug(); bq.debug(); lq.debug(); print_debug(q); print_debug(bq); print_debug(lq); return 0; }
// for test int main(int argc, char **argv) { Quote q("asd", 10.5); Bulk_Quote b_q("f**k", 10.5, 20, 0.2); Quote *p; p = &q; cout << "20本asd的总价格为:" << p->net_price(20) << endl; p->debug(); p = &b_q; cout << "20本f**k的总价格为:" << p->net_price(20) << endl; p->debug(); system("pause"); return 0; }
double print_total(ostream &os, const Quote &item, size_t n) { double ret = item.net_price(n); os << "ISBN: " << item.isbn() << " # sold: " << n << " total due: " << ret << endl; item.debug(); return ret; }
void print_debug(const Quote &q) { q.debug(); }
void print_debug(const Quote& item) { item.debug(); }