From 4d678be508b9b1a92b0224d90019249f5ade12a8 Mon Sep 17 00:00:00 2001 From: wsb <1234@qq.com> Date: Sun, 9 Apr 2023 09:49:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=9F=BA=E7=B1=BBdog?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- dog.cpp | 25 +++++++++++++++++++++++++ dog.h | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 dog.cpp create mode 100644 dog.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 71c5e78..2ac9835 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 Animal.cpp Animal.h) +add_executable(cpp_12_polymorphic main.cpp Animal.cpp Animal.h dog.cpp dog.h) diff --git a/dog.cpp b/dog.cpp new file mode 100644 index 0000000..fa5b470 --- /dev/null +++ b/dog.cpp @@ -0,0 +1,25 @@ +// +// Created by 11010 on 2023/4/9. +// + +#include "dog.h" +#include "Animal.h" + +dog::dog() : Animal() { + +} + +dog::dog(string color, string food) : Animal(color, food) { + this->color = color; + this->food = food; +} + +dog::dog(string name, string color, string food) : Animal(name, color, food) { + this->name = name; + this->color = color; + this->food = food; +} + +void dog::run() { + cout << name + "具有跑的能力" << endl; +} diff --git a/dog.h b/dog.h new file mode 100644 index 0000000..e7d4de6 --- /dev/null +++ b/dog.h @@ -0,0 +1,24 @@ +// +// Created by 11010 on 2023/4/9. +// + +#ifndef CPP_12_POLYMORPHIC_DOG_H +#define CPP_12_POLYMORPHIC_DOG_H +#include +#include +#include "Animal.h" + +using namespace std; + +//狗类,继承animal类 +class dog: public Animal{ +public: + dog(); + dog(string color,string food); + dog(string name,string color,string food); + + void run(); +}; + + +#endif //CPP_12_POLYMORPHIC_DOG_H -- GitLab