zoukankan      html  css  js  c++  java
  • C++虚函数表调用学习

    知识点是看 陈皓大哥的博客,代码也参考了他的,不过做了很小的改动。

    原文链接:http://blog.csdn.net/haoel/article/details/1948051

    #include "stdio.h"
    
    class Base
    {
    public:
    	virtual void Fun1()
    	{
    		printf("Call Base Fun1
    ");
    	}
    	virtual void Fun2()
    	{
    		printf("Call Base Fun2
    ");
    	}
    	virtual void Fun3()
    	{
    		printf("Call Base Fun3
    ");
    	}
    private:
    	virtual void Fun4()
    	{
    		printf("Call Base Fun4
    ");
    	}
    };
    
    class Derived : public Base
    {
    public:
    	virtual void Fun1()
    	{
    		printf("Call Derived Fun1
    ");
    	}
    	virtual void Fun5()
    	{
    		printf("Call Fun5
    ");
    	}
    };
    
    typedef void(*Fun)(void);
    
    void main(void)
    {
    	Derived lDerived;
    
    	int** lpVtableAdd = (int**)&lDerived;
    
    
    	for (int i = 0; i< 5; ++i)
    	{
    		Fun lpFun = (Fun)(lpVtableAdd[0][i]);
    
    		lpFun();
    	}
    
    	printf("First add of Base:%d, and first virtual Fun add:%d
    ",(int*)(&lDerived),&lpVtableAdd);
    
    }
    


    看懂了这些代码 应该对虚函数表就清楚啦吧,O(∩_∩)O~

  • 相关阅读:
    python的Collections 模块
    python模块
    python类
    python异常
    python文件处理
    python函数
    python字符串
    python数据结构
    python循环
    下载Google Play外国区APP技巧
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3228679.html
Copyright © 2011-2022 走看看