博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
虚函数与纯虚函数的代码解读——2
阅读量:4485 次
发布时间:2019-06-08

本文共 902 字,大约阅读时间需要 3 分钟。

#include 
 
#include 
 
#include 
#include 
 
#include 
#include 
#include 
 
 
using namespace std;
 
class Base
{
public:
Base() {cout << "Base con" << endl;}
virtual ~Base()
{
cout << "Base destructor" << endl;
}
virtual void Hiberarchy() const = 0;
};
 
void Base::Hiberarchy() const//pure virtual also can have function body
{
cout << "Base::Hiberarchy" << endl;
}
 
 
class Derived : public Base
{
public:
Derived() {cout << "Derived con" << endl;}
virtual void Hiberarchy() const
{
Base::Hiberarchy();
cout << "Derived::Hiberarchy" << endl;
}
 
//    virtual ~Derived()
~Derived()
{
cout << "Derived destructor" << endl;
}
virtual void foo(){cout << "Derived foo()" << endl;}
};
 
int main()
{
Base *pb = new Derived();
pb->Hiberarchy();
pb->Base::Hiberarchy();
 
delete pb;
Derived derivedObj;
derivedObj.foo();
//cout <<  << endl;
return 0;
}
 

 
 
 

转载于:https://www.cnblogs.com/guxuanqing/p/4908842.html

你可能感兴趣的文章
相册分类列表页
查看>>
各浏览器的鼠标位置测试
查看>>
[BZOJ1070][SCOI2007]修车(最小费用最大流)
查看>>
python字节码(转)
查看>>
[bzoj 2151]种树(贪心)
查看>>
js函数
查看>>
Unity3D 之UGUI 图片
查看>>
Django中模型(一)
查看>>
心得体会2
查看>>
Agile实践日志一 -- Grooming Session
查看>>
msgsnd的一个小问题
查看>>
Spring实现动态数据源,支持动态加入、删除和设置权重及读写分离
查看>>
iOS 浅谈:深.浅拷贝与copy.strong
查看>>
BZOJ 3555: [Ctsc2014]企鹅QQ
查看>>
C++和JAVA的关系 (转载)
查看>>
JMeter在linux上分布式压测步骤(二)
查看>>
ClassNotFoundException和NoClassDefFoundError区别
查看>>
我问你,一个程序发三遍是什么毛病
查看>>
企业网站的重构
查看>>
javaScript 深拷贝、浅拷贝
查看>>