#include <iostream> #include <cstring> using namespace std; class Person { protected: char Name[]; char Sex; int Age; public: void Register(char *name, int age, char sex); void ShowMe(); }; class Teacher:public Person { private: char Dept[]; i
1. 继承体系中关于对象释放遇到的问题描述 1.1 手动释放 关于时间记录有很多种方法,因此为不同的计时方法创建一个TimeKeeper基类和一些派生类就再合理不过了: class TimeKeeper { public: TimeKeeper(); ~TimeKeeper(); ... }; class AtomicClock: public TimeKeeper { ... }; class WaterClock: public TimeKeeper { ... }; class Wrist
引言: 我们都知道类的一个很明显的特性是多态,比如我们声明一个水果的基类: class Fruit { public: Fruit() {}; ~Fruit(){}; } 那么我们根据这个Fruit基类可以派生出以下的子类: class Apple:public Fruit{}; class Orange:public Fruit{}; 那么问题来了,如果我们想经由一个基类指针去删除一个派生类Apple,且我们有以下的方法 Fruit * foo(){ Apple * p = new Apple