size of an empty class

F

free2cric

Hi,
What will the syntax sound like for checking size of an empty class?
what will be the size.
Thanks,
Cric
 
S

Srini

Hi,
What will the syntax sound like for checking size of an empty class?
what will be the size.
Thanks,
Cric

#include <iostream>

class A
{
};

int main()
{
std::cout << sizeof(A);
return 0;
}

Srini
 
M

msalters

WittyGuy schreef:
What is the advantage of using empty class?

Empty classes do not have to take up space when used as base classes.
E.g. an empty class deriving from two empty base classes can also be
1 byte.

The main reason "really" empty classes (i.e. nothing between the { }
and
no base classes ) are in the language is that it would take an extra
rule
to disallow them. That's not worth it

HTH,
Michiel Salters
 
I

Imre Palik

WittyGuy said:
What is the advantage of using empty class?

No advantage. Either you need it & use it, or don't need it & don't
use it.

They are used oft with template metaprogramming or as abstract base
classes.

ImRe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top