C++实函数、虚函数、纯虚函数、函数重写
和以前一样,先做好准备工作。代码和以前差不多。
首先是父类,People;
头文件:
#ifndef PEOPLE_H
#define PEOPLE_H
#include<iostream>
using namespace std;
class People{
public:
People();//默认是构造方法
People(int age, int sex);
int get_age();
int get_sex();
void say_hello();
private:
int age;
int sex;
};
#endif // PEOPLE_H
主文件: