Advertisement
Guest User

Untitled

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