I’m a Java programer lost in C++ and pointers 😀
I have an array of pointers to Bucket-Objects
Bucket<E>* index = new Bucket<E>[2];
I initialize it like this:
index[0] points to Bucket1
index[1] points to Bucket2
And then I want to double the size of the array and link the additional entries like this:
index[0] points to Bucket1
index[1] points to Bucket2
index[2] points to Bucket1
index[3] points to Bucket2
I have this code so far, which generates copies of the Bucket-Objects and I don’t want that!
for (size_t i = 0; i < newSize; ++i)
{
if (i < oldIndexSize)
newIndex[i] = index[i];
else
newIndex[i] = index[i - oldIndexSize];
}
No, you have a pointer to an array of Bucket objects. An array of pointers to Bucket objects would look like this:
A dynamically allocated array of pointers to bucket objects would be declared like this:
But what you should probably be using is a vector of shared pointers to bucket objects, like this: