Suppose I have the following Foo class. The size of Foo's member variables are what I would expect. However, the size of Foo it'self is 16. Where are the extra four bytes coming from?
#include <iostream>
#include <string>
using namespace std;
class Foo {
public:
int *data;
int length;
};
int main() {
Foo f;
cout << "Size of foo's data: " << sizeof(f.data) << endl;
cout << "Size of foo's length: " << sizeof(f.length) << endl;
cout << "Size of foo: " << sizeof(f) << endl;
return 0;
}
Output:
Size of foo's data: 8
Size of foo's length: 4
Size of foo: 16