Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. class Base {
  5. public:
  6. virtual void Test() {
  7. std::cout << "Base";
  8. }
  9.  
  10. };
  11.  
  12. class Child : public Base{
  13. public:
  14. void Test() {
  15. std::cout << "Child";
  16. }
  17. };
  18.  
  19.  
  20. void polyTest(Base x) {
  21. int ptr = *(int*)&x;
  22. typedef void(*func)(void*);
  23.  
  24. func testFunc = (func)(*(int*)(ptr));
  25. testFunc(&x);
  26. }
  27.  
  28. int main(int argc, char const *argv[])
  29. {
  30. Child foo;
  31.  
  32. polyTest(foo);
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement