My C++ class has data members of string and int. I thought its size is 36 bytes but the output says 40 bytes. Could someone explain?
#include <iostream>
using namespace std;
class SizeTest {
private:
std::string name;
int i;
};
int main(int argc, char** argv) {
cout<<"sizeof(SizeTest) is : " << sizeof(SizeTest)<<endl;
}
Output:
sizeof(SizeTest) is : 40