📄 stlshape.cpp
字号:
//: C20:Stlshape.cpp
// From Thinking in C++, 2nd Edition
// at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Simple shapes w/ STL
#include <vector>
#include <iostream>
using namespace std;
class shape {
public:
virtual void draw() = 0;
virtual ~shape() {};
};
class circle : public shape {
public:
void draw() { cout << "circle::draw\n"; }
~circle() { cout << "~circle\n"; }
};
class triangle : public shape {
public:
void draw() { cout << "triangle::draw\n"; }
~triangle() { cout << "~triangle\n"; }
};
class square : public shape {
public:
void draw() { cout << "square::draw\n"; }
~square() { cout << "~square\n"; }
};
typedef std::vector<shape*> container;
typedef container::iterator iter;
int main() {
container shapes;
shapes.push_back(new circle);
shapes.push_back(new square);
shapes.push_back(new triangle);
for(iter i = shapes.begin();
i != shapes.end(); i++)
(*i)->draw();
// ... Sometime later:
for(iter i = shapes.begin();
i != shapes.end(); i++)
delete *i;
return 0;
} ///:~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -