多层继承中的虚函数
来源:互联网 发布:变号王软件下载 编辑:程序博客网 时间:2024/05/17 08:39
//Source filename: Win32Con.cpp
#include <iostream>
using namespace std;
class parent1
{
public:
virtual int fun1(){
cout<<"parent1::fun1()"<<endl;return 0;
};
virtual int fun2()=0;
};
class child1:public parent1
{
public:
virtual int fun1()
{
cout<<"child1::fun1()"<<endl;
parent1::fun1();
return 0;
}
virtual int fun2()
{
cout<<"child1::fun2()"<<endl;
return 0;
}
};
class grandson:public child1
{
public:
virtual int fun2()
{
cout<<"grandson::fun2()"<<endl;
//parent1::fun2();
parent1::fun1();
child1::fun2();
return 0;
}
};
void test_func1(parent1 *pp)
{
pp->fun1();
pp->fun2();
}
int main(int argc, char* argv[])
{
grandson sunzi;
test_func1(&sunzi);
return 0;
}
#include <iostream>
using namespace std;
class parent1
{
public:
virtual int fun1(){
cout<<"parent1::fun1()"<<endl;return 0;
};
virtual int fun2()=0;
};
class child1:public parent1
{
public:
virtual int fun1()
{
cout<<"child1::fun1()"<<endl;
parent1::fun1();
return 0;
}
virtual int fun2()
{
cout<<"child1::fun2()"<<endl;
return 0;
}
};
class grandson:public child1
{
public:
virtual int fun2()
{
cout<<"grandson::fun2()"<<endl;
//parent1::fun2();
parent1::fun1();
child1::fun2();
return 0;
}
};
void test_func1(parent1 *pp)
{
pp->fun1();
pp->fun2();
}
int main(int argc, char* argv[])
{
grandson sunzi;
test_func1(&sunzi);
return 0;
}
- 多层继承中的虚函数
- C++在多层继承中调用虚函数
- C++在多层继承中调用虚函数
- Java中多层继承中的方法重写
- 多层继承当中构造函数对虚函数表指针的初始化
- 多继承中的虚函数
- 多继承中的虚函数
- C++中的继承、虚函数、内联函数
- 多重继承中的纯虚函数“妙用”
- 虚函数在类继承中的用法
- 谈谈c++中继承中的虚函数
- 继承中的非虚成员函数
- 继承关系中的虚函数表
- c++中的多重继承和虚函数
- 继承中的函数覆盖
- 继承中的虚析构函数
- ThinkPHP模板多层继承
- Hibernate多层继承配置
- 曲线拟合——最小二乘法
- tinyxml使用总结
- Flex3实战 11章应用程序导航
- WinForm基础:省份选择器
- 内存字节对齐
- 多层继承中的虚函数
- 省ACM竞赛终于拿了个银牌。
- Linux Kernel & Distributions
- oracle10g代码中内置了BULK COLLECT limit为100
- JAVA 多线程相关
- 在eclipse里导入项目方法
- C++内存布局生成步骤
- 如何对类中的protected方法进行单元测试
- Information about ora.OC4J in Rac Environment