Why is the size of an empty class 1 byte? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
23rd Nov 2019, 5:48 AM
Sonic
Sonic - avatar
4 Answers
+ 13
Sonic when an empty class is created In c++ then that contain no string variable or integer but when we create the object of that empty class some memory is assigned for unique address of objects so for that reason 1 byte memory allocation is done for the empty class even if you create an empty function in the empty class then too memory allocation is done 1 byte to that empty class which is allocated for unique adddress identification just an warning will appear of function return nothing which is obvious https://code.sololearn.com/c4et815PLuB7/?ref=app
23rd Nov 2019, 6:00 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 8
Sonic hello. Good question.👍 Try this post: https://stackoverflow.com/a/621648/7959868
23rd Nov 2019, 6:01 AM
Manual
Manual - avatar
+ 6
https://code.sololearn.com/c9jU78Lv3XcK/?ref=app Hope this helps too...
23rd Nov 2019, 9:18 AM
Ve Sudhakaran
+ 1
Sonic I do not know the answer but what if you create an object of this class? Will it have no memory allocated?
23rd Nov 2019, 5:59 AM
Avinesh
Avinesh - avatar