#include "iostream"
using namespace std;
class Shape
{
public:
virtual int GetName() const=0;
};
class Circle: public Shape
{
public:
virtual int GetName() const
{
cout << "circle" <<endl;
return 0;
}
};
class Line: public Shape
{
public:
virtual int GetName() const
{
cout << "line" <<endl;
return 0;
}
};
void Show (Shape &s)
{
s.GetName();
}
int main(void)
{
Line *l = new Line();
Circle *c = new Circle();
Show( *l );
Show( *c) ;
return 0;
}
C++纯虚函数接口
最新推荐文章于 2024-07-10 21:50:31 发布