| SameerThigale (90) | |||
How come the output is 24???In Visual Studio 2010 Explain in detail please | |||
|
|
|||
| Cubbi (1583) | |
|
It is entirely compiler- and platform-specific. I get: with XLC on AIX: 32 bytes in 32-bit mode, 56 bytes in 64-bit mode with GCC on Linux: 24 bytes in 32-bit mode, 40 bytes in 64-bit mode with Sun Studio on Solaris: 24 bytes in 32-bit mode, 48 bytes in 64-bit mode Looking at the 24 bytes of 32-bit gcc's ans sun's layout, which happens to be identical, I see (each line is 4 bytes) derived1::_vptr derived1::j derived2::_vptr derived2::k derived::sum base::i but other compilers, obviously, do other things. | |
|
Last edited on
|
|
| SameerThigale (90) | |||
What about this code? why is the output different?
Visual Studio 2010 | |||
|
|
|||
| Framework (3116) | |||
In addition to Cubbi's reply, the size of an unpacked structure is influenced by the size of each member, the VTP (virtual table pointer), and any possible alignment padding the compiler added between the members. Since a compiler may re-arrange a classes data members in any way it wants, it may affect the the result of the "sizeof( )" operator.
Because "derived2 has a VTP, and "derived1" does not. Wazzak | |||
|
|
|||
| SameerThigale (90) | |
|
I'm a newbie to this "Virtual Classes" topic.. I'm using C++ Complete Reference by Herb Schildt and it doesn't include any such topic in detail | |
|
|
|
| Framework (3116) | |
|
Ah, that's not the best book in the world. In fact, it's a terrible book. As it does not cover virtual inheritance, it's not a complete reference. Bin it -- literally. Wazzak | |
|
|
|