Sobes.tech
Middle

How much space does an object of an empty class occupy in C++?

sobes.tech AI

Answer from AI

1 byte (assuming the class has no virtual functions).

This is because each object in C++ must have a unique address in memory for mechanisms like pointers to work correctly. Allocating 1 byte satisfies this requirement.

If the class has at least one virtual function, the object will occupy more space (at least the size of a pointer to the virtual function table, vtable), even if there are no other data members.