diff --git a/Animal.cpp b/Animal.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f7db5e2edc550bd73a8f905bf458ada5ee4d3eaa --- /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 96402aa49c1f1fd53af17c4000070bbb1afe55b0..71c5e78835b41fa094bced4c25c066e93a8e3387 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)