#include "iostream"
#include "vector"
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::string;
class Shape
{
public:
virtual void Get() = 0;
};
class Line: public Shape
{
public:
virtual void Get()
{
cout << "Line Get" <<endl;
}
};
class Circle: public Shape
{
public:
virtual void Get()
{
cout << "Circle Get" <<endl;
}
};
void Show (vector<Shape*> &v)
{
for (vector<Shape*>::iterator it = v.begin(); it != v.end(); ++it)
{
(*it)->Get();
}
}
int main(void)
{
vector<Shape*> arg;
Shape *s0 = new Line();
Shape *s1 = new Circle();
arg.push_back(s0);
arg.push_back(s1);
Show ( arg);
return 0;
}
c++接口与容器结合
最新推荐文章于 2024-05-17 17:49:53 发布