阅读程序2
来源:互联网 发布:photoshop cs6破解mac 编辑:程序博客网 时间:2024/05/21 06:58
#include <iostream>using namespace std;class Mammal{public: Mammal( ) { cout<<"Mammal constructor called."<<endl; } virtual ~Mammal()//虚析构函数 { cout<<"Mammal destructor called."<<endl; } virtual void Speak() const//虚函数 { cout<<"Mammal speak."<<endl; }};class Dog : public Mammal{public: Dog() { cout<<"Dog constructor called."<<endl; } ~Dog() { cout<<"Dog destructor called."<<endl; } void Speak() const { cout<<"Woof!"<<endl; }};int main(){ Mammal *p=new Dog; p->Speak(); delete p; return 0;}
运行结果:
心得:
此程序先调用基类构造函数,再调用派生类构造函数,然后再调用指针变量指向的对象的同名函数,再调用派生类虚构函数,最后调用基类虚构函数。
- noip2012 阅读程序2
- 阅读程序(2)
- 11-阅读程序2
- 阅读程序2
- 程序阅读2
- 程序阅读2
- 程序阅读(2)
- 阅读程序1、2
- 补充阅读程序-2
- 阅读程序2
- 阅读程序2
- 阅读程序(2)
- 阅读程序2
- 阅读程序2
- 阅读程序2
- 阅读程序(2)
- 阅读程序(2)
- 阅读程序2
- spring @Autowired @Qualifier
- flex饼图
- android布局中更换控件顺序后无法正常运行的解决办法
- Linux内核 do_fork 函数源代码浅析
- selenium webdriver学习(十三)------------如何利用Actions类模拟鼠标和键盘的操作
- 阅读程序2
- IE8兼容视图(IE7 mode)与独立IE7的区别
- QT中获取天气预报json数据
- 设计模式之单列模式:简单实现
- JS函数闭包
- 微妙
- Android SurfaceFlinger中的SharedClient & threadLoop Paint--留UML图用
- ArcGIS10+SkecthUp8之间的交互使用
- eclipse 快捷键