Topic: question about class size, help?
Author: kuehl@uzwil (Dietmar Kuehl)
Date: 1995/06/16 Raw View
lmr (ren@math.ohio-state.edu) wrote:
: g++ compiled program tells me that sizeof(A)=1.
: Why 1 and what is this byte used for (storing ...??).
This correspond to a requirement by the C++ standard proposal that an
empty object has nonzero size (chapter 9 verse 3):
A class with an empty sequence of members and base class objects is an
empty class. Objects of an empty class have a nonzero size.
: If I add several virtual functions, the sizeof(A) becomes 4, what are
: those four bytes for? A pointer to where the virtual functions are?
Yes: If virtual functions are used these have to be dispatched at run
time. This could be done using a pointer to a table (the virtual
function table) where the actual address of the function is looked up.
There are other concepts around but I think it is sufficient and legal
to imagine the use of virtual functions this way.
dk
--
http://www.informatik.uni-konstanz.de/~kuehl
dietmar.kuehl@uni-konstanz.de
I am a realistic optimist - that's why I appear to be slightly pessimistic
Author: ren@math.ohio-state.edu (lmr)
Date: 1995/06/16 Raw View
If I define an empty class such as:
class A{
};
g++ compiled program tells me that sizeof(A)=1.
Why 1 and what is this byte used for (storing ...??).
If I add several virtual functions, the sizeof(A) becomes 4, what are
those four bytes for? A pointer to where the virtual functions are?
Many thanks
--
Liming Ren |
Dept. of Mathematics | 231 West 18th Avenue
The Ohio State University | Columbus, Ohio43210