特殊工具和技术
- 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;
}