Every new object that is created from this struct uses the same location for "Buffer.buf". When I create an object from this struct I want to have a unique "Buffer.buf" ready for each creation, which I dont get at the moment. Maybe someone have time to give me a small explantation on why?
I know I can create the object first, then assign "new char[2000] to objectName.Buffer.buf and the assign will be unique for each object. But is it possible to have this ready and done when the object is created?
Every new object that is created from this struct uses the same location for "Buffer.buf".
The code you have there will make each ClientInfo().Buffer.buf point to a different array of 2000 chars. I don't know what you might be seeing that makes you think they all point to a single array.
ClientInfo C;
map <int, ClientInfo> Clients;
Clients[2] = C; // Doesn't this create a copy of the object and store it in Clients[2]?
Clients[2].Buffer.buf[0] = 'a';
Clients[22] = C;
Clients[22].Buffer.buf[0] = 'c'; // This changes the value of Clients[2], i dont know why
cout << Clients[2].Buffer.buf[0]; // = 'c'
You're copying an object into another, where the class of both contains a pointer and doesn't have a user-defined copy constructor or assignment operator. The result is that you're copying one pointer onto another. It's essentially the same as