fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Foo{
  5. int foo;
  6. public:
  7. Foo() : foo(13) {}
  8. int getFoo() const { return foo; }
  9. };
  10.  
  11. union Bar{
  12. Foo fBar;
  13. double dBar;
  14. };
  15.  
  16. int main() {
  17. Bar bar = { Foo() };
  18.  
  19. cout << bar.fBar.getFoo() << endl;
  20. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
13