提交 4d678be5 编写于 作者: W wsb

创建基类dog类

上级 796f4c2b
......@@ -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)
//
// 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;
}
//
// Created by 11010 on 2023/4/9.
//
#ifndef CPP_12_POLYMORPHIC_DOG_H
#define CPP_12_POLYMORPHIC_DOG_H
#include <iostream>
#include <string>
#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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册