0

Say I have:

class Foo {
  union {
     double a;
     std::string b;
  };
};

What will the default constructor generated by the compiler do? My understanding of the C++ standard is that primitives are not initialized but objects are. So what happens here?

Community
  • 1
  • 1
Pol
  • 3,848
  • 1
  • 38
  • 55

1 Answers1

4

The default constructor (as well as the copy constructor, assignment operator and destructor) for the union is implicitly declared deleted, and so is the constructor of Foo. You'll see this once you try to actually create an instance of Foo.

Igor Tandetnik
  • 50,461
  • 4
  • 56
  • 85