Fetch the repository succeeded.
/************************************************************************************
* @file: OCpc.cpp
* @author: Fang XS.
* @version: v1.0
* @date: Create on 2022-07-09, Modified on xxxx-xx-xx
* @brief Open Close printciples example.
***********************************************************************************/
#include <iostream>
using namespace std;
/* abstract class as an interface */
class ToEat{
public:
virtual void UseChopsticks() = 0;
};
/** called by the caller
* extends
* \Depend on the interface
*/
class Meat : public ToEat{
public:
virtual void UseChopsticks(){
cout << "Use Chopsticks to eat meat..." << endl;
}
};
class Rice : public ToEat{
public:
virtual void UseChopsticks(){
cout << "Use Chopsticks to eat rice..." << endl;
}
};
/** caller
* \Depend on the interface
*/
class human : public ToEat{
public:
virtual void UseChopsticks(){
;
}
virtual void UseChopsticks(ToEat *te){
te->UseChopsticks();
}
};
int main(void)
{
human * zs = new human();
zs->UseChopsticks(new Meat);
zs->UseChopsticks(new Rice);
delete zs;
zs = NULL;
/* Pause the External console*/
system("pause");
}
/*********************************** END OF FILE ***********************************/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。