Pushok

vtable

Jun 18th, 2015
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A{
  5.     public:
  6.     virtual void foo(){
  7.         cout << "Hallo A\n";
  8.     }
  9.    
  10.     virtual void bar(){
  11.         cout << "Bar A\n";
  12.     }
  13.    
  14. };
  15.  
  16. class B : A{
  17.     public:
  18.     virtual void foo(){
  19.         cout << "Hallo B\n";
  20.     }
  21. };
  22.  
  23. typedef void (*foo_ptr)();
  24.  
  25. int main() {
  26.     // your code goes here
  27.     B a;
  28.     //a.foo();
  29.     void** ref = *(void***)&a;//vtable
  30.     ((foo_ptr)ref[1])();
  31.    
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment