Reputation: 13
Is there a method of calculating size of c++ class. when i create a object of this below class ,size of object is 24 byte.
class student
{
student* pointer;
char * c;
student* AnotherPointer;
class SubClass
{
int a,b;
};
};
and now removing Subclass from student class,i am still getting size of Student class object is 24. why it is not changing??
class student
{
student* pointer;
char * c;
student* AnotherPointer;
};
Upvotes: 0
Views: 649
Reputation: 238311
Is there a method of calculating size of c++ class.
You can use the sizeof
operator to get the size of a class, or any other type. For example:
std::cout << sizeof(student);
removing Subclass
Note that the class named Subclass
is not a "subclass". It is a nested class.
why it is not changing??
Because you made no changes to sub objects of the class. A nested class is not a sub object. It is in fact not an object at all - it is a type.
Upvotes: 2