类的构造函数与析构函数调用顺序
2015-06-30 12:40
190 查看
#include <stdio.h> #include <Windows.h> class Base { public: Base() { printf("I am base !\n"); } void play(); virtual void eat(); virtual ~Base() { printf("I am ~base !\n"); } }; void Base::play() { printf("I am base play !\n"); } void Base::eat() { printf("I am base eat !\n"); } class Sun : public Base { public: Sun() { printf("I am sun !\n"); } ~Sun() { printf("I am ~sun !\n"); } void play(); void eat(); }; void Sun::play() { printf("I am sun play !\n"); } void Sun::eat() { printf("I am sun eat !\n"); } int main() { Base *b = new Base; Base *p = new Sun; Sun *s = new Sun; b->play(); b->eat(); p->play(); p->eat(); s->play(); s->eat(); delete b; delete p; delete s; b = NULL; p = NULL; s = NULL; system("pause"); return 0; }
输出结果:
相关文章推荐
- hdoj2037_今年暑假不AC(贪心)
- HTML DOM innerHTML和write的区别
- smarty模板
- VB实现的《QQ美女找茬游戏》作弊器实例
- vs2010的专业版下载免激活
- NTP服务器的配置
- 二分图
- [java]引用类型传的是地址
- [java]求质数
- 使用 SSDB 来实现操作频率限制
- [java]利用函数自动排序数组并逆序
- [java]数组最小值前置,其他顺序不变
- Socket Client端的思路
- ERROR: Partitioning option license required to run sessions with user-defined partition points.
- android logcat输出
- [华为机试练习题]18.矩阵相乘
- ubuntu14 部署zookeeper3.4.6启动失败
- chilkat9.5破解
- [java]冒泡算法:让数字从小到大排序
- Linux模块化机制和module_init