Virtual base class

Feb 5, 2014 at 9:03am
Hello,

what is the size of object of Class child in following case?

class Parent
{

};
class Child : virtual public Parent
{

};
Feb 5, 2014 at 9:06am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

class Parent
{

};
class Child : virtual public Parent
{

};

int main()
{
    std::cout << sizeof(Child) << '\n' ;
}


It is what it is.
Feb 5, 2014 at 9:22am
thanx cire for reply.

yes you are right.

size become 4 byte(depend on compiler).

right?
Feb 5, 2014 at 9:27am
Yes.

You might find some interesting reading here:
http://stackoverflow.com/questions/2038717/object-size-with-virtual
Feb 5, 2014 at 9:39am
yes its because Child class contain one vptr. because its virtual base class inheritance.

So, what that vptr stored?
means whose address it store?

address of VTable for Parent class?
Feb 6, 2014 at 5:14am
Hi cire,

waiting for reply...
Topic archived. No new replies allowed.