Abhi
Abhi

Reputation: 1

Inheritance-Finding size of an object of a class

I have to find the size of an object of a derived class.But the thing is do I have to count the size of private members since object has only access to public members?

Thanks in advance.

Upvotes: 0

Views: 52

Answers (1)

François Andrieux
François Andrieux

Reputation: 29023

sizeof tells you the size of an object, regardless of inheritance. Summing the size of members will not give you a reliable size for your object, it doesn't account for padding between those members or other size overhead. Private members, even inherited ones, contribute to the size of the object in the same way public members do.

The usage is sizeof(obj) or sizeof(type).

Upvotes: 1

Related Questions