函数指针调用
来源:互联网 发布:js面向对象 继承例子 编辑:程序博客网 时间:2024/06/05 20:52
#include <iostream>
using namespace std;
class Base
{
public :
virtual void Print() { cout<<"This is Base"<<endl;}
};
// void PrintB() { cout<<"This is base printb"<<endl;}
class Base2
{
public:
virtual void Print2() {cout <<"This is base2"<<endl;}
};
class Derived: public Base,public Base2
{
public:
void Print() {cout<<"This is Derived"<<endl;}
void Print2() {cout<<"This is Derived2"<<endl;}
void Out() {cout<<"This should not be called"<<endl;}
};
typedef void (*Func)();
int main()
{
Base *pb = new Derived();
return 0;
}
using namespace std;
class Base
{
public :
virtual void Print() { cout<<"This is Base"<<endl;}
};
// void PrintB() { cout<<"This is base printb"<<endl;}
class Base2
{
public:
virtual void Print2() {cout <<"This is base2"<<endl;}
};
class Derived: public Base,public Base2
{
public:
void Print() {cout<<"This is Derived"<<endl;}
void Print2() {cout<<"This is Derived2"<<endl;}
void Out() {cout<<"This should not be called"<<endl;}
};
typedef void (*Func)();
int main()
{
Base *pb = new Derived();
// Derived *db = new Derived();
pb->Print();
//基类不能调用基类中没有virutal的子类函数
//pb->Out();
//db->PrintB();int* pA = (int*)(*((int*)pb+1));
//将地址强制转换成函数指针
Func pFunc = (Func)*pA;
//调用地址即调用函数指针
pFunc();return 0;
}
0 0
- 通过指针调用函数?
- 函数指针调用
- 函数指针 的调用
- 函数指针调用
- 指针调用函数实例
- 函数指针的调用
- C++函数,指针调用
- 函数指针调用
- 调用函数,返回指针
- 通过函数指针调用函数
- 用函数指针调用函数
- 用函数指针调用函数
- 用函数指针调用函数
- 通过函数指针调用函数
- 函数指针作函数参数/用函数指针调用函数
- this指针和函数调用
- Purebasic用指针调用函数
- 调用类中的函数指针
- UUID的意义和作用
- GCC 显示程序详细编译-链接过程
- spring 中自带的字符编码集过滤器
- 特征选择
- linux关于动态库链接小记
- 函数指针调用
- chrome里debug network的timing说明(翻译官网)
- 宿主手机联系人、通话记录、短信工具类(不断完善中。。。)
- 泛型
- 如何遍历Hashtable
- oracle分页查询及rownum的使用
- 1003 Problem C
- ecshop各种报错汇总
- 20160616-------听的同时想一下