I have the following code
class nest_empty
{
class empty{};
};
Will the size of nest_empty be 1 (on my implementation sizof an empty class is 1)? If yes why? Can nest_empty be considered as an empty class?
EDIT:
class nest_empty
{
class empty{};
empty d;
};
Will the size of nest_empty still be 1? If yes why?
Your first version of
nest_emptyis an empty class (no non-static data members, and no non-empty bases), so if they have size 1 in your implementation, it has size 1.“Why” is because empty classes have size 1 on your implementation, which in turn is because they can’t have size 0 (the standard forbids it), and your implementer has chosen 1.
Your second
nest_emptyis not an empty class (it has a non-static data member). It could legally have size 1, since its only non-static data member,d, is of typeempty, which is an empty class and hence presumably of size 1.I can’t tell you whether it actually will have size 1 on your implementation, though. Ask your compiler.