提交 af22b4c0 编写于 作者: W wsb

创建基类cat类

上级 4d678be5
......@@ -3,4 +3,4 @@ project(cpp_12_polymorphic)
set(CMAKE_CXX_STANDARD 11)
add_executable(cpp_12_polymorphic main.cpp Animal.cpp Animal.h dog.cpp dog.h)
add_executable(cpp_12_polymorphic main.cpp Animal.cpp Animal.h dog.cpp dog.h cat.cpp cat.h)
//
// Created by 11010 on 2023/4/9.
//
#include "cat.h"
cat::cat() :Animal(){
}
cat::cat(string color, string food) : Animal(color, food),
color(color),food(food) {
}
cat::cat(string name, string color, string food) :Animal(name, color, food),name(name),
color(color),food(food) {
}
void cat::run() {
cout << name + "¾ßÓÐÅܵÄÄÜÁ¦" << endl;
}
//
// Created by 11010 on 2023/4/9.
//
#ifndef CPP_12_POLYMORPHIC_CAT_H
#define CPP_12_POLYMORPHIC_CAT_H
#include <iostream>
#include <string>
#include "Animal.h"
using namespace std;
//̬ˈ
class cat :public Animal{
string name;
string color;
string food;
public:
cat();
cat(string color,string food);
cat(string name,string color,string food);
void run();
};
#endif //CPP_12_POLYMORPHIC_CAT_H
......@@ -12,6 +12,10 @@ using namespace std;
//¹·À࣬¼Ì³ÐanimalÀà
class dog: public Animal{
string name;
string color;
string food;
public:
dog();
dog(string color,string food);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册