Pushok icon

vtable

Pushok | PRO | 06/18/15 12:32:13 PM UTC | 0 ⭐ | 512 👁️ | Never ⏰ | []
C++ |

410 B

|

None

|

0 👍

/

0 👎

#include <iostream>
using namespace std;
 
class A{
    public:
    virtual void foo(){
        cout << "Hallo A\n";
    }
    
    virtual void bar(){
        cout << "Bar A\n";
    }
    
};
 
class B : A{
    public:
    virtual void foo(){
        cout << "Hallo B\n";
    }
};
 
typedef void (*foo_ptr)();
 
int main() {
    // your code goes here
    B a;
    //a.foo();
    void** ref = *(void***)&a;//vtable
    ((foo_ptr)ref[1])();
    
    return 0;
}

Comments