Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. class Base
  2. {
  3. public:
  4. int a;
  5. Base()=default;
  6. Base( int _a):a(_a){}
  7.  
  8. void Print() { cout << "Value: " << a << endl; }
  9. };
  10.  
  11. class Derived1: public Base
  12. {
  13. public:
  14. int d;
  15.  
  16. Derived1(): d( 0x11223344){}
  17. };
  18.  
  19. union U
  20. {
  21. U(){}
  22. Base base;
  23. Derived1 derived1;
  24. } u;
  25.  
  26. int main()
  27. {
  28. memset( &u, 0, sizeof(u));
  29.  
  30. new (&u) Base(12345678);
  31. u.base.Print();
  32.  
  33. new (&u) Derived1;
  34. u.base.Print();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement