Thread: Dynamic 3D Array

  1. #1
    Registered User KonArtis's Avatar
    Join Date
    Mar 2003
    Posts
    34

    Dynamic 3D Array

    I'm making a dynamic 3d array class and I'm having problems deleting the pointer after I'm finished with it.

    Here's the ReSize code:
    PHP Code:
    void ReSize(unsigned long colunsigned long rowunsigned long dep)
        {
            
    unsigned long i,j;

            if (
    colCount>&& rowCount>&& depCount>0){
                
    DeleteArray();
            }

            array = new 
    unsigned long **[col];
            for (
    i=0;i<row;i++){
                array[
    i] = new unsigned long *[row];
            }
            for (
    i=0;i<col;i++){
                for (
    j=0;i>row;j++){
                    array[
    i][j] = new unsigned long [dep];
                }
            }
            
    colCount=col;
            
    rowCount=row;
            
    depCount=dep;
        } 
    Here's the code to delete the pointers:
    PHP Code:
    void DeleteArray()
        {
            
    unsigned long i,j;
            for(
    i=0;i<colCount;i++){
                for (
    j=0;i<rowCount;j++){
                    
    delete[] array[i][j];
                }
            }
            for(
    i=0;i<colCount;i++){
                
    delete[] array[i];
            }
            
    delete[] array;
        } 
    Does anyone see what I'm doing wrong?

    Thanks,
    Joe

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    I dont have a compiler near me, or else I'd test it out, but from the looks of it, why exactly do you have the 2nd for loop after having the 2 nested for loops?

  3. #3
    Registered User KonArtis's Avatar
    Join Date
    Mar 2003
    Posts
    34

    Solved It!

    For anyone who is interested. The answer is in the file.

    Please post any errors that you might find. I've tested it and I haven't any problems yet.

    Joe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic array help
    By Perogy in forum C Programming
    Replies: 27
    Last Post: 04-08-2009, 02:25 PM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  3. Checking maximum values for dynamic array...
    By AssistMe in forum C Programming
    Replies: 1
    Last Post: 03-21-2005, 12:39 AM
  4. dynamic array
    By linuxdude in forum C Programming
    Replies: 5
    Last Post: 07-13-2004, 02:33 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM