passing a 2dim dynamically allocated array to a funct

This is a discussion on passing a 2dim dynamically allocated array to a funct within the C++ Programming forums, part of the General Programming Boards category; i'm not even sure this is possible, as you have to specify the size of the second dimension. any clues? ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    106

    passing a 2dim dynamically allocated array to a funct

    i'm not even sure this is possible, as you have to specify the size of the second dimension. any clues? thanks.

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    heh? once its allocated it works the same as your previous thread .

    BTW...if the question is that closely similar to your previous topic just put it there.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >i'm not even sure this is possible
    It sure would be irritating if it weren't possible:
    Code:
    void f ( int **array );
    
    int main()
    {
      int **a = new int*[5];
      for ( int i = 0; i < 5; i++ )
        a[i] = new int[5];
      f ( a );
    }
    A good way to remember how to declare your function parameters is to look at how the object being passed was declared. In this case "int **name". In the case of a two dimensional array "T name[x][y]". It's much easier that way, you don't have to remember obscure rules.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    106
    thanks for the help guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help passing nxn array to 2d array.
    By beglaryanh in forum C Programming
    Replies: 2
    Last Post: 06-06-2009, 05:23 PM
  2. How To Declare and Dynamically Size a Global 2D Array?
    By groberts1980 in forum C Programming
    Replies: 26
    Last Post: 11-15-2006, 08:07 AM
  3. File I/O problem for dynamically allocated struct array
    By veecee in forum C++ Programming
    Replies: 2
    Last Post: 05-05-2006, 09:28 PM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

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