3,980 questions
The compiler did not allocate any memory for your class. What it did do is determine how many bytes of storage it would take if such a class was created. I suggest you read sizeof-operator
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I read:
The memory space is allocated to the data members of a class only when an object of the class is declared, and not when the data members are declared inside the class.
>
Why does sizeof(Base) 44?
I didn't create an instance of the Base class and expected the compiler doesn't allocate memory for Base.
Please see the following code:
#include <iostream>
using namespace std;
class Base
{
public:
void Print() {
cout << "In Base..";
}
int a;
int arr[10];
};
int main() {
cout << sizeof(Base) << endl; // 44
return 0;
}
The compiler did not allocate any memory for your class. What it did do is determine how many bytes of storage it would take if such a class was created. I suggest you read sizeof-operator