I have a struct of type Duplicate
I have a variable of type int called stringSize, it has a value of 5
I am creating a dynamic array:
Duplicate *duplicates;
duplicates = new Duplicate[stringSize - 1];
Later I delete[] duplicates;
I’m getting one member in that array only? I’ve verified that stringSize – 1 = 4 with a debug walk through. What can I do to get the 4 members I need?
Any help appreciated,
Thanks // 🙂
Indeed gives you
duplicates[0-3](AssumingstringSize - 1is 4, like you say). How are you determining you’re getting less?I suspect you may be doing something like:
sizeof(duplicates) / sizeof(duplicates[0]), and on an off-change getting one. The above code only works for statically allocated arrays, wheresizeof(duplicates)would match the size of the array, in bytes. In your case, it’ll simply return the size of a pointer on your system. (duplicatesis aDuplicate*)And mandatory: Use
std::vectorif this is “real” code.Your debugger is doing the best it can. As far is it’s concerned, you’ve merely got a pointer to some data. Consider:
How should the debugger, just given a pointer, know if it’s pointing to an array or just one value? It cannot, safely. (It would have to determine, somehow, if the pointer was to an array, and the size of that array.)