If I have:
std::size_t bagCapacity_ = 10;
std::size_t bagSize = 0;
A** bag = new A*[bagCapacity_];
while (capacity--)
{
bag[capacity] = new A(bagSize++); //**here I'm loading this array from the end is it ok?**
}
And also can I delete those object from starting at the end of the array?
while (capacity--)
{
delete bag[capacity];
}
Question in a code.
Yes, that is fine. You can fill the elements anyway you like.
This code is wrong. bag[capacity] is of type
A*which is allocated usingnewand notnew[]hence you should not dodelete[]you should do onlydelete bag[capacity];to delete individualAobjects. At the end you should bedelete[] bagto delete the memory allocated for the bag.