PROBLEM Unable to understand the variation in size of object All the code is tested under Borland C++ ver 3.1 In borland V3.1 the int takes two bytes Lets look at the following code Class base { public: int b; base() {} virtual void f() {} virtual void g() {} }; Class derive : virtual public base { public: int d; derive() {} virtual void f() {} virtual void g() {} };
……………… derive d; cout<gives 12 why? /* But if I don’t give constructors in derive then the size of derive class object is 10, because there will be no 2 bytes extra in object layout as shown below. Please help me out about finding the myth of these extra two bytes. */
Object-Layout V-TABLE
|------------| |------------|
---|ptr to base | -->|derive::f |
| |------------| | |------------|
| |derive v-ptr|-------| |derive::k |
| |------------| |------------|
| |d | ->|derive::f |
| |------------| | |------------|
| |0 |<-- | |base::g |
| |------------| | | |------------|
-->|base-vptr |---|----|
|------------| |
|b | |
|------------| |**what the hell is this**
Please reply at: Contact: informfarid@yahoo.com ------------------------------------------------------------ In the middle of dificulty lies oppurtunity.