From 796f4c2b1dc68b4a6baeb55325d967797f551d8b Mon Sep 17 00:00:00 2001 From: wsb <1234@qq.com> Date: Sun, 9 Apr 2023 09:38:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=9F=BA=E7=B1=BBanimal?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Animal.cpp | 22 ++++++++++++++++++++++ Animal.h | 26 ++++++++++++++++++++++++++ CMakeLists.txt | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Animal.cpp create mode 100644 Animal.h diff --git a/Animal.cpp b/Animal.cpp new file mode 100644 index 0000000..f7db5e2 --- /dev/null +++ b/Animal.cpp @@ -0,0 +1,22 @@ +// +// Created by 11010 on 2023/4/9. +// + +#include "Animal.h" + +Animal::Animal() { + +} + +Animal::Animal(string c, string f):color(c),food(f) { + +} + +//动物具有跑的能力 +void Animal::run() { +cout< +#include + +using namespace std; + +//创建动物类: 作为狗类和猫类的基类 +class Animal { +public: + string name; + string color; + string food; + Animal(); + Animal(string c,string f); + Animal(string n,string c,string f); + void run(); +}; + + +#endif //CPP_12_POLYMORPHIC_ANIMAL_H diff --git a/CMakeLists.txt b/CMakeLists.txt index 96402aa..71c5e78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,4 +3,4 @@ project(cpp_12_polymorphic) set(CMAKE_CXX_STANDARD 11) -add_executable(cpp_12_polymorphic main.cpp) +add_executable(cpp_12_polymorphic main.cpp Animal.cpp Animal.h) -- GitLab