dynamically allocating 2D arrays

This is a discussion on dynamically allocating 2D arrays within the C++ Programming forums, part of the General Programming Boards category; ok, so my programming partner and I just found out that you can't dynamically allocate a 2d array in C++. ...

  1. #1
    Neo
    Neo is offline
    Registered User
    Join Date
    Nov 2003
    Posts
    8

    dynamically allocating 2D arrays

    ok, so my programming partner and I just found out that you can't dynamically allocate a 2d array in C++. like this

    Code:
    char* charPtr;
    
    charPtr = new char[someVariable][someVariable2];
    C++ says no. Does anyone know a way around this?

    we already have a bunch of code based around it and we need a fix.

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904

  3. #3
    Neo
    Neo is offline
    Registered User
    Join Date
    Nov 2003
    Posts
    8
    sorry I didn't catch that in the FAQ. it has been months since I have read that thing. THANKS.

  4. #4
    Neo
    Neo is offline
    Registered User
    Join Date
    Nov 2003
    Posts
    8
    another quick question on the 2D array problem. how would you dereference something in that?

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >how would you dereference something in that?
    Save yourself a migraine and use subscripting just like a two dimensional array:
    Code:
    array[x][y] = someval;
    cout<< array[x][y];
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Allocating a number of large 3d arrays in C
    By Surrender in forum C Programming
    Replies: 22
    Last Post: 08-19-2008, 09:36 AM
  2. dynamically allocating 4D arrays
    By Marv in forum C Programming
    Replies: 15
    Last Post: 04-12-2007, 01:34 AM
  3. Dynamically Allocating a 2D Array.
    By LightsOut06 in forum C Programming
    Replies: 17
    Last Post: 10-09-2005, 01:55 AM
  4. 2D Dynamically allocated pointer arrays
    By Lionmane in forum C Programming
    Replies: 37
    Last Post: 06-11-2005, 11:39 PM
  5. Dynamically allocated arrays
    By axe786 in forum C Programming
    Replies: 6
    Last Post: 12-03-2004, 01:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21