#include <iostream>
using namespace std;
// 静态多态 可以用函数重载实现,或,模板
class CBeer
{
public:
void Show()
{
cout << "CBeer::Show" << endl;
}
};
class CMilk
{
public:
void Show()
{
cout << "CMilk::Show" << endl;
}
};
class CCoffee
{
public:
void Show()
{
cout << "CCoffee::Show" << endl;
}
};
void Bottle(CBeer* p)
{
p->Show();
}
void Bottle(CMilk* p)
{
p->Show();
}
void Bottle(CCoffee* p)
{
p->Show();
}
int main()
{
CBeer* beer = new CBeer;
CMilk* milk = new CMilk;
CCoffee* coffee = new CCoffee;
Bottle(beer);
Bottle(milk);
Bottle(coffee);
system("pause");
return 0;
}
静态多态
最新推荐文章于 2024-06-04 14:19:28 发布