C++虛函數和純虛函數（2）

 `class` `shape` `{` `public` `:` `shape(){};` `virtual` `void` `draw() = 0;` `virtual` `~shape(){cout << ` `"shape destruction"` `<< endl;}` `};` `class` `rectangle : ` `public` `shape` `{` `public` `:` `rectangle(){};` `void` `draw()` `{` `}` `~rectangle(){cout << ` `"rectangle destruction"` `<< endl;}` `};` `class` `round : ` `public` `shape` `{` `public` `:` `round(){};` `void` `draw()` `{` `}` `~round(){cout << ` `"round destruction"` `<< endl;}` `};` `void` `main()` `{` `shape * s;`
 `    ` `s = ` `new` `rectangle();` `s->draw();` `delete` `s;` `s = ` `new` `round();` `s->draw();` `delete` `s;` `}`

§純虛函數

 `class` `shape` `{` `public` `:` `shape(){};` `virtual` `void` `draw()=0;　　　　` `//純虛函數` `};` `class` `rectangle : ` `public` `shape` `{` `public` `:` `rectangle(){};` `void` `draw()` `{` `畫方形;` `}` `};` `class` `round : ` `public` `shape` `{` `public` `:` `round(){};` `void` `draw()` `{` `畫圓形;` `}` `};` `void` `main()` `{` `shape * s;` `s = ` `new` `rectangle();` `s->draw();` `s = ` `new` `round();` `s->draw();` `} `