can anybody tell me why the size of an empty class is 1
-
can anybody tell me why the size of an empty class is 1.and i also want to know why we cant create an object for an abstract class. Thanks in advance
-
can anybody tell me why the size of an empty class is 1.and i also want to know why we cant create an object for an abstract class. Thanks in advance
C++ requires freestanding empty objects to have non-zero size. Most compilers automatically insert a
char
into "empty" objects to satisfy this. However, if your emptyclass
is a baseclass
then it won't add any size to the derivedclass
object. See: http://msdn2.microsoft.com/en-us/library/f42z47h2(VS.80).aspx[^] You cannot create an object directly from an abstractclass
since it contains virtual method(s) without implementation(s)."We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Monday, December 10, 2007 3:25:41 PM
-
can anybody tell me why the size of an empty class is 1.and i also want to know why we cant create an object for an abstract class. Thanks in advance
Giving them the smallest possible non-zero size makes sure different objects result in different pointer/reference values, which is what you hope to get isn't it? :)
Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't get e-mail notifications.
-
can anybody tell me why the size of an empty class is 1.and i also want to know why we cant create an object for an abstract class. Thanks in advance
philiptabraham wrote:
i also want to know why we cant create an object for an abstract class
If you could, the class wouldn't be abstract. It doesn't make sense to create an object of a class that has virtual functions that are NULL. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
modified on Monday, December 10, 2007 3:15:35 PM
-
philiptabraham wrote:
i also want to know why we cant create an object for an abstract class
If you could, the class wouldn't be abstract. It doesn't make sense to create an object of a class that has virtual functions that are NULL. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
modified on Monday, December 10, 2007 3:15:35 PM
Mark Salsbery wrote:
It doesn't make sense to create an object of a class that doesn't have a complete implementation.
You can make a class non-copyable by declaring a private copy constructor (and assignment operator) without an implementation!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
Mark Salsbery wrote:
It doesn't make sense to create an object of a class that doesn't have a complete implementation.
You can make a class non-copyable by declaring a private copy constructor (and assignment operator) without an implementation!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
right. badly worded - I changed it a bit. It took a long time for CP to let me edit it (or reply to you :)). Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: