Results 1 to 3 of 3

Thread: 2D array pointers

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2001
    Posts
    60

    2D array pointers

    Hey

    Ive been trying to use a 2d Array pointers heres what ive done so far im trying to create a 2d array pointer of type Obj:

    [/Start of code]
    struct Obj
    {
    float speed,x,y;
    int r,g,b;
    bool isDrawn;
    };

    class cBuilding
    {
    Obj **bld;
    etc......
    };

    cBuilding::cBuidling()
    {
    bld = new Obj*[21]; //Pointers to 21 arrays
    for (int c=0; c<21; c++)
    {
    bld[c] = new Obj[7]; //Creates an array for each pointer in bld array
    }

    }

    cBuilding::~cBuilding()
    {
    for (int c=0; c<21; c++)
    {
    delete [] bld[c];
    }

    delete [] bld;

    }


    [/End of code]

    it just crashes my program please help me im desperate :D

    Thanks

    Chris
    What is Life? One big dream or one Big nightmere.

  2. #2
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    where does it crash?
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    That's not a 2d array but an array of arrays. I recommend you use a single array and dynamically dimension it into 2d, so that you can access it by bld[a+b*width];
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width