1.虚函数
1.1虚函数的作用
虚函数的作用是允许在派生类中重新定义与基类同名的函数,并且可以通过基类指针或引用来访问基类和派生类中的同名函数。
class Time{
public:
Time(int=0,int=0,int=0);
void show();
protected:
int hour;
int min;
int sec;
};
class LocalTime:public Time{
public:
LocalTime(int=0,int=0,int=0,string="+8");
void show();
protected:
string zone;
};
Time::Time(int h,int m,int s):hour(h),min(m),sec(s){}
void Time::show(){
cout<&l......
阅读全文