Hi,
I am writing a c++ simulation program and have come accross a bug, so i ask the follwing question.
I have the following class
Code:
class Client{
public:
struct packet
{
int more;
};
packet *transfer
}
Code:
int main{
Client *cl;
cl = new Client [numOfCli];
cin >> const;
cl[0].transfer = new Client::packet [const];
cl[1].transfer = new Client::packet [const];
return 0;
}
My question is will the above code work as intended?
I ask this because I thought when memory is allocated for the "cl" array
Code:
cl = new Client[numOfCli];
, the compiler does not yet know the size of the "transfer" array, so how does it know how much memory to allocate for the "cl" array.
In my program I am getting problems where variables such as "more" above are changing unexpectably, so I thought maybe there is a memory overlap somwhere.