Created
July 29, 2015 13:55
-
-
Save garymacindoe/580e15c765923feee703 to your computer and use it in GitHub Desktop.
Calling a private method through the vtable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class A { | |
virtual void function() const { | |
std::cout << "You bastard!" << std::endl; | |
} | |
}; | |
int main() { | |
A a; | |
std::size_t * ptr = *(std::size_t **)&a; | |
((void (*)())ptr[0])(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works in clang 3.6 and gcc 5 compiled with
-std=c++11 -pedantic -Wall -Wextra
.