Help with implementing a function to change size of dynamic array
        Posted  
        
            by 
                iRobot
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by iRobot
        
        
        
        Published on 2011-02-13T22:43:36Z
        Indexed on 
            2011/02/13
            23:25 UTC
        
        
        Read the original article
        Hit count: 192
        
c++
I'm trying to write a function that will change the size of a dynamic array to a new size. In my header file, I have:
Image **images; //pointer to a dynamic array of image pointers
int maximum; //size
I want to do this by allocating a new array and copying the values over without changing their indices. If there are non-null pointers outside the range newmax, then we cant do this. So heres what I have:
There are no compilation or runtime errors. However, I find that the new array isnt getting sized right. When I run the following test case:
I should get an index out of bounds error, but instead the system lets it slide. Can anyone see the mistake? I've looked for hours but cant find anything.
© Stack Overflow or respective owner