It seems the object is always 32 byte long nomatter what the string is. Is the string actaully in heap and the variable name is really just a pointer to a dynamic string array?
I am asking because I want to send structs over WinSock and I need to cast a Char Buffer[] into a struct.
#include <iostream>
#include <string>
using namespace std;
struct Obj{
string name;
};
void main(){
Obj test1, test2;
test1.name = "123";
test2.name = "1234";
cout << "test1: " << sizeof(test1) << " " << test1.name << endl;
cout << "test2: " << sizeof(test2) << " " << test2.name << endl;
test1.name = "12345678901234567890123456789012345678901234567890";
test2.name = "test1234aedgegy";
cout << "test1: " << sizeof(test1) << " " << test1.name << endl;
cout << "test2: " << sizeof(test2) << " " << test2.name << endl;
system("pause");
}