1 Star 0 Fork 0

Fang XS./CPP_CodeRoad

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
OCpc.cpp 1.28 KB
Copy Edit Raw Blame History
Fang XS. authored 2022-07-09 15:46 +08:00 . OpenClosepc code commit
/************************************************************************************
* @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 ***********************************/
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/shun-int/CPP_Notes.git
git@gitee.com:shun-int/CPP_Notes.git
shun-int
CPP_Notes
CPP_CodeRoad
master

Search