Multidimensional Arrays and Pointers

Having Trouble Creating a pointer to a multidimensional array.

Page 1 of 1

1 Replies - 10416 Views - Last Post: 03 August 2007 - 10:13 PM Rate Topic: -----

#1 LzBy1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 25-July 07

Multidimensional Arrays and Pointers

Post icon  Posted 03 August 2007 - 09:44 PM

Hey, Guys Right now I'm having trouble creating a pointer to a multidimensional array. I can create a multidimensional array, or create a pointer to an array, but I can't create a pointer that points to a multidimensional array. I'll include the code of what works and what does.

bool grid[5][5];
//Works (creating a multidimensional array of the bool type

bool *grid = new bool[5];
//Works (creating a pointer to a single dimensional array of the bool type)

bool *grid = new bool[5][5];
//doesn't work (creating a pointer to a multidimensional array of the bool type)



Note: The compiler error I get is: error C2440: 'initializing' : cannot convert from 'bool (*)[5]' to 'bool *'

How do I create a pointer to a multidimensional array? Do I have to declare the array and pinter separately? PLEASE HELP.

Is This A Good Question/Topic? 0
  • +

Replies To: Multidimensional Arrays and Pointers

#2 LzBy1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 25-July 07

Re: Multidimensional Arrays and Pointers

Posted 03 August 2007 - 10:13 PM

I figured it out.

This is very helpful.

Here is the working code.
bool (*grid)[5] = new bool[5][5];


Was This Post Helpful? 1

Page 1 of 1