Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Base
- {
- public:
- int a;
- Base()=default;
- Base( int _a):a(_a){}
- void Print() { cout << "Value: " << a << endl; }
- };
- class Derived1: public Base
- {
- public:
- int d;
- Derived1(): d( 0x11223344){}
- };
- union U
- {
- U(){}
- Base base;
- Derived1 derived1;
- } u;
- int main()
- {
- memset( &u, 0, sizeof(u));
- new (&u) Base(12345678);
- u.base.Print();
- new (&u) Derived1;
- u.base.Print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement