提交 796f4c2b 编写于 作者: W wsb

创建基类animal类

上级 326db46a
//
// 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<<name+"具有跑的能力"<<endl;
}
Animal::Animal(string n, string c, string f):name(n),color(c),food(f) {
}
//
// Created by 11010 on 2023/4/9.
//
#ifndef CPP_12_POLYMORPHIC_ANIMAL_H
#define CPP_12_POLYMORPHIC_ANIMAL_H
#include <iostream>
#include <string>
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
......@@ -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)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册