B
Bob
Try the following code
class basic
{
public:
virtual void one()=0;
};
class derived1ublic basic
{
public:
virtual void two()=0;
};
class derived2ubilc base
{
public:
virtual void three()=0;
};
class component : public derived,public derived2
{
public:
void one(){ cout<<sizeof(*this);}
void two(){cout<<sizeof(*this);}
void three(){cout<<sizeof(*this);}
};
void main()
{
//
basic * b = (derived1*)new component;
cout<<*b;
b->one();
}
My question is why size of *b and size of *this are different.
sizeof(*b) will give the size of the base class (4)while
sizeof(*this)gives the size of component class(8) although the pointer
used here is *b i.e basic class pointer.
regards,
Bob
class basic
{
public:
virtual void one()=0;
};
class derived1ublic basic
{
public:
virtual void two()=0;
};
class derived2ubilc base
{
public:
virtual void three()=0;
};
class component : public derived,public derived2
{
public:
void one(){ cout<<sizeof(*this);}
void two(){cout<<sizeof(*this);}
void three(){cout<<sizeof(*this);}
};
void main()
{
//
basic * b = (derived1*)new component;
cout<<*b;
b->one();
}
My question is why size of *b and size of *this are different.
sizeof(*b) will give the size of the base class (4)while
sizeof(*this)gives the size of component class(8) although the pointer
used here is *b i.e basic class pointer.
regards,
Bob