p2-128.cpp
来自「c++200源代码」· C++ 代码 · 共 40 行
CPP
40 行
#include<iostream.h>
//定义最低层基类First,它作为其他类的基类
class First {
int val1;
public:
First() {
cout<<"The First initialized"<<endl;
}
~First() {
cout<<"The First destroyed"<<endl;
}
};
//定义派生类Second,它作为其他类的基类
class Second :public First { //默认为private模式
int val2;
public:
Second() {
cout<<"The Second initialized"<<endl;
}
~Second() {
cout<<"The Second destroyed"<<endl;
}
};
//定义最上层派生类Three
class Three :public Second {
int val3;
public:
Three() {
cout<<"The Three initialized"<<endl;
}
~Three() {
cout<<"The Three destroyed"<<endl;
}
};
//main()函数中测试构造函数和析构函数的执行情况
main() {
Three t1;
cout<<"---- Use the t1----"<<endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?