#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;
}
转载:https://blog.csdn.net/weixin_44656803/article/details/101455892
查看评论