virtual function table in c++
来源:互联网 发布:阮佳网络班视频 编辑:程序博客网 时间:2024/06/02 00:58
what is vfptr?
The follow codes show u it.
#include <stdint.h>#include <iostream>class base {public: virtual void func1() { std::cout << "base::func1" << std::endl; } virtual void func2() { std::cout << "base::func2" << std::endl; }};typedef void (base::*virtual_func)(void);void test_virtual_table() { char base_addredd[sizeof(base)] = {0}; base *b = new(base_addredd)base; std::cout <<"The address prealloced is 0x" << std::hex << (intptr_t)base_addredd << std::endl; std::cout <<"base's address is 0x" << std::hex << b << std::endl; intptr_t **__vfptr = *reinterpret_cast<intptr_t***>(b); virtual_func* pfuncs = reinterpret_cast<virtual_func*>(__vfptr); virtual_func v_func1 = pfuncs[0]; virtual_func v_func2 = pfuncs[1]; std::cout << "function found by vftable" << std::endl; (b->*v_func1)(); // maybe g++ implement virtual function table differently with virtual studio,this line will crash down // the messageis: Segmentation fault (core dumped) // (b->*v_func2)(); std::cout << "end" << std::endl; void (*p_temp)(void) = (void (*)(void))(&base::func1); p_temp(); }int main() { std::cout << "base's size is " << sizeof(base) << std::endl; test_virtual_table(); return 0;}
0 0
- virtual function table in c++
- 【C++】template vs virtual function
- C++: Pure Virtual Function Called
- 虚表(C++)virtual table
- 虚表(C++)virtual table
- 虚表(C++)virtual table
- c / c++ virtual function and pure virtual function summarize
- non-virtual thunk for Virtual Function in multiple inheritance
- non-virtual thunk for Virtual Function in multiple inheritance
- How Virtual Table works in C++
- Question 48: In C++, which of the following statements accurately describe a base class destructor calling a virtual function ov
- virtual function
- Virtual function
- virtual function
- virtual function
- Virtual Function
- memcached.c: In function ‘add_iov’:
- How do virtual functions work in C++?
- [JAVA基础]String的format
- 按字典序生成{1,2,...,n}的r子集的算法-组合数学
- 递归算法——求Fibonacci数列前n项(Java实现&C语言实现)
- Apple HLS: comparing versions
- 关于javascript中的this
- virtual function table in c++
- 各大网络请求框架的比较
- ssh框架整合基础配置
- Gradle 指定仓库位置或工作目录
- 提问的智慧
- Rxjava
- 机器学习算法实践-算法原理-EM算法
- 在字符串中删除特定的字符(字符串)。 题目:输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。 例如,输入”They are students.”和”aeiou”, 则删除之后的第一个字符串
- 非常不错的ffmpeg的解说