struct st{
string name;
};
int main() {
st s1[10];
{
st s2[10];
for (int i = 0; i < 10; i++) {
s2[i].name = "name";
}
memcpy(&s1, &s2, sizeof(s2));
}
for (int i = 0; i < 10; i++) {
cout << s1[i].name << endl;
}
return 0;
}
The above code successfully prints out the "name" ten times, but the seg-faults instead of terminating. I'm suspecting it has to do with the destructor for s2, but not sure. How should I deal with this?