Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / multidimentional arrays

Author
Message
shiny
20
Years of Service
User Offline
Joined: 17th Jan 2004
Location: Santa Monica
Posted: 15th Jun 2005 20:34
So sorry I have resorted to asking like a baby, but I have been trying to fix this all night! This is a ultra diluted version of what I'm trying to do - pass a 3d array of pointers to a function, and have that function assign another array of pointers to the same array. Why am I getting an error message? whats with the "int *[][30][30]" ?? Anyone experienced with multi dimentional arrays and pointers willing to help? Thanks!



I get the following error

error C2440: '=' : cannot convert from 'int *[][30][30]' to 'int *[30][30][30]'

OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 15th Jun 2005 21:58
I had thought casting to a single int pointer may work, but it appears incorrect pointers are passed.

At the moment, I cant think of anything.

Troll Fiddler
19
Years of Service
User Offline
Joined: 19th Jan 2005
Location: Mayo, Ireland
Posted: 16th Jun 2005 01:03 Edited at: 16th Jun 2005 01:08
Not quite sure what you're trying to do there. You can't assign to array identifiers as they are just pointers to the start of the array. That is, you can't assign an array identifier to point somewhere else.

If you just want to do something with the array contents then you can just pass the array identifier to your function. In effect you are passing a pointer. You'd also need to pass the array size to your function as it's not the actual array being passed, just the pointer.






T.
shiny
20
Years of Service
User Offline
Joined: 17th Jan 2004
Location: Santa Monica
Posted: 16th Jun 2005 02:43 Edited at: 16th Jun 2005 03:02
Thanks! Maybe I should have been clearer though. This was just a simulation of a class. I wanted the class to hold a pointer to the array as one of its data members, and the assignment would occur in the contructor of the class.

Any thoughts?

Oh another way i could do this is to create some kind of global array that is accesable from everywhere in the entire program, including classes. I don't know how to do that though...

Sephnroth
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 16th Jun 2005 03:40
maybe i missunderstood, but if you want a global array accessiable everywhere in the entire program then just declare it out of the function somewhere and in a header extern it, then everywhere that wants to get at it just needs to include the header in the same source?

[07:16:59-pm] « Sephnroth » you were dreaming about lee...
[07:17:13-pm] « Mouse » stfu
[07:17:22-pm] « Mouse » he was hanging himself lol
shiny
20
Years of Service
User Offline
Joined: 17th Jan 2004
Location: Santa Monica
Posted: 16th Jun 2005 03:52
Oh super awesome! That saves sooooo much time... I was passing this huge 3d array all over the place and all I needed to do was declare it in a header file and include that file in each place I wanted to access it from!

Fantastic.

Thanks.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Jun 2005 03:52
My take on your requirements:



Avoid all of that low-level memory nonsense - use a vector. Then you don't need to get the copy constructor, operator= or destructor correct.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
scooby bloke
19
Years of Service
User Offline
Joined: 4th Nov 2004
Location:
Posted: 16th Jun 2005 19:38
I've just done this using a vector, and created a template class to handle it. Means that I can create a 2d vector class of any object type, and can get / set the items using simple ->getAt(x,y) methods. Works a treat

Have a look here...

http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraskdr/html/askgui04162002.asp

Even allows you to dynamically grow the size of the arrays created. The example is 2d, but it could be easily modified to handle 3d arrays...

Cheers,
Iain
shiny
20
Years of Service
User Offline
Joined: 17th Jan 2004
Location: Santa Monica
Posted: 17th Jun 2005 11:49
thanks!!! Problem solved and I'm well under way with my game : ).

*resists the urge to swamp the helpfull people with other questions*

Login to post a reply

Server time is: 2024-04-19 14:32:00
Your offset time is: 2024-04-19 14:32:00