1. 程式人生 > >《C++ primer 》 獵豹網校 特殊工具與技術 2018/10/9

《C++ primer 》 獵豹網校 特殊工具與技術 2018/10/9

特殊工具和技術

  • allocator類
  • PTTI
  • 類成員的指標
  • 巢狀類
  • union
  • 區域性類
  • 位域
  • volatile
  • exter "C"
#include <iostream>
using namespace std;
class Item_base
{
public:
    virtual double net_price(size_t n) const;
    {
        return n* price;
    }
public:
    std::string isbn;
protected:
    double price;
};

class Bulk_item: public Item_base
{
public:
    double net_price(std::size_t cnt)
    {
        if(cnt>min_qty)
        return cnt * price;
    }
private:
    std::size_t min_qty;
    double discount;
};

int main()
{
    Item_base *pItem = new Item_base();

    allocator<Item_base> a;     //分配記憶體
    a.allocator(100);
    system("pause");
    return 0;
}