size of object ?

what is the size of object in c++ , if there is no data member in the class ?
sizeof is required to return 1. This gets messy with inheritance/virtual inheritance/virtual functions though...
Last edited on
sizeof is required to return at least 1.

Of course, implementations usually use the smallest possible value which satisfies this criterium.

Andy

From the standard:

Unless it is a bit-field (9.6), a most derived object shall have a non-zero size and shall occupy one or more bytes of storage. Base class subobjects may have zero size. An object of trivially copyable or standard-layout type (3.9) shall occupy contiguous bytes of storage.
Last edited on
@Nabeel Nazir

what is the size of object in c++ , if there is no data member in the class ?


It has a non-zero size.

Let assume that you decided to define an array of such a type. If the size of an object of a class without non-static data members would be equal to zero then the array had zero size and there would not be any sense to access elements of the array by index.
Topic archived. No new replies allowed.