Thread: Confused Deleting 2D array

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Confused Deleting 2D array

    I've read through similar posts on deleting 2D arrays, but still a little confused.

    I have a global array that I want to delete in a funtion named DeleteGroup():

    Code:
    //global variables:
    int FragArray[75][4];
    char PKAGroupName[500];
    char PKAGroupFrag[500];
    
    void DeleteGroup() {
     
    	PKAGroupName[0] = '\0';
    	PKAGroupFrag[0] = '\0';
    
    	for (int i = 0; i < 75; i++){
    		delete[] FragArray[i];
    	}
    
    	delete[] FragArray;
    
    	return;
    
    }
    
    other function {
     sets values in array,
    calls DeleteGroup() to clear/delete Frag array when finished
    }
    When I compile my code, I get the warning:
    Code:
    warning C4154: deletion of an array expression; conversion to pointer supplied
    I can't figure out what I'm doing wrong?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I've read through similar posts on deleting 2D arrays, but still a little confused.
    You don't delete arrays. If an array goes out of scope, the compiler manages that for you.

    You only delete things which you did new on.
    You only delete[] things which you did new[] on.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    Thanks again Salem. I'll read up on new[]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  2. Help with mallocing a 2d array please?
    By Gatt9 in forum C Programming
    Replies: 5
    Last Post: 10-10-2008, 03:45 AM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Comparing a 2d Array (newbie)
    By Cockney in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2001, 12:15 PM