Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C/C++

C/C++ C/C++ Discussion

Reply
 
Thread Tools Display Modes
Old 04-05-2007, 08:47 PM   #1 (permalink)
Master of the Internet
 
Joeku's Avatar
 
Join Date: Feb 2005
Location: ShatteredSosaria.com
Posts: 9,226
Default Multidimensional Array as a parameter

Alright, so I have the following:
Code:
// Sort the Table.
void SortTable( int dims, int Table[][], int pos, int start, int end )
{
It's giving me a compile error...
Quote:
declaration of `Table' as multidimensional array must have bounds for all dimensions except the first
Table should have a size of 100 for the first dimension, and "dims" for the second.

How should I write this?
Joeku is offline   Reply With Quote
Old 04-05-2007, 09:10 PM   #2 (permalink)
Forum Expert
 
Join Date: Aug 2004
Location: Redmond, WA
Age: 21
Posts: 1,288
Send a message via AIM to Sep102 Send a message via MSN to Sep102
Default

You can't specify it like that if you need the second dimension to vary. Basically, C++ doesn't support multi-dimensional arrays. It supports arrays of arrays and not very well at that. Arrays are essentially just pointers, therefore it follows that arrays are just pointers to pointers. That is how you will need to pass it, as an int **.

Also, that error was referring to the fact that you don't actually specify the length of the rightmost dimensions of the array. What it wants you to do is specify the array like: int a[][10], with the rightmost dimensions explicit. Adding a third dimension gives something like: int a[][10][10]. If you don't know what the rightmost dimensions are, then you can't specify the parameter as an array.

Last edited by Sep102; 04-05-2007 at 09:14 PM.
Sep102 is offline   Reply With Quote
Old 04-06-2007, 06:53 PM   #3 (permalink)
Master of the Internet
 
Joeku's Avatar
 
Join Date: Feb 2005
Location: ShatteredSosaria.com
Posts: 9,226
Default

So it's completely impossible to have a multidimensional array with variable rightmost dimensions as a parameter?

Joeku is offline   Reply With Quote
Old 04-06-2007, 08:13 PM   #4 (permalink)
Administrator
 
Zippy's Avatar
 
Join Date: Aug 2002
Location: Baltimore, MD
Age: 25
Posts: 4,831
Default

No, he gave you the answer:

Code:
void SortTable( int dims, int **Table, int pos, int start, int end )
Add one star for every dimension of the array.

The empty square bracket (int blah[]) notation is less widely used and means *almost* the exact same thing... its usually better to avoid it.
__________________
Zippy, Razor Creator and RunUO Core Developer
The RunUO Software Team

"Intuition, like a flash of lightning, lasts only for a second. It generally comes when one is tormented by a difficult decipherment and when one reviews in his mind the fruitless experiments already tried. Suddenly the light breaks through and one finds after a few minutes what previous days of labor were unable to reveal."
~The Cryptonomicon

Zippy is offline   Reply With Quote
Old 04-06-2007, 09:57 PM   #5 (permalink)
Forum Expert
 
Join Date: Feb 2005
Age: 24
Posts: 985
Send a message via AIM to Nochte
Default

On this same topic, do any of ya'll have any idea how to teach the concept of 4+D arrays? Hell, 3D arrays are hard enough to draw on a whiteboard...
__________________
Quote:
Originally Posted by kkjjkk View Post
how sad you people call yourselves scripters and you can't even format an emulator game into something completely differnt....no wounder y'all are stuck here with no real scripting jobs unlike me. please go back to school.
QFDA
Nochte is offline   Reply With Quote
Old 04-06-2007, 10:53 PM   #6 (permalink)
RunUO Forum Moderator
 
daat99's Avatar
 
Join Date: Dec 2004
Location: Israel
Age: 27
Posts: 8,163
Send a message via ICQ to daat99 Send a message via AIM to daat99
Default

Quote:
Originally Posted by Nochte View Post
On this same topic, do any of ya'll have any idea how to teach the concept of 4+D arrays? Hell, 3D arrays are hard enough to draw on a whiteboard...
Well, I don't know of an easy way to draw it on a whiteboard but assuming the students already know what 1d array is I describe it as follows:
2 dimensional array is simply 1 dimensional array where each item in it isn't a normal item but another 1 dimensional array.
The same can be said that any N dimensional array is simply 1 dimensional array where each item in it is an N-1 dimensional array (recursion should bump in just about now to fill the rest).

If you really have to draw it I would draw 2 dimensional array (matrix) and mark each item with a letter (line) and number (row), then I would draw 2 dimensional arrays (matrices) and title them with the letter and number in the first matrix (I won't suggest doing it for more then 2x2x2x2).

Just tell them to imagine that each matrix is a zoom-in presentation of 1 block in the original matrix.

Personally I won't even try to have the students imagine a 4 dimensional array, it'll eat up all lesson time and leave them totally confused.


P.S.
Quote:
Originally Posted by Zippy View Post
The empty square bracket (int blah[]) notation is less widely used and means *almost* the exact same thing... its usually better to avoid it.
Zippy can you please elaborate on the differences between the [] operator and the *operator in those cases?
__________________
I always try to help
Sometimes, I don't know how....

My Web Page
Forum Rules
-------------------------------------------------------------
Extensive OWLTR System | Token System | World Teleporters
-------------------------------------------------------------

Last edited by daat99; 04-06-2007 at 11:01 PM.
daat99 is offline   Reply With Quote
Old 04-07-2007, 12:29 AM   #7 (permalink)
Forum Expert
 
Join Date: Feb 2005
Age: 24
Posts: 985
Send a message via AIM to Nochte
Default

Quote:
Originally Posted by daat99 View Post
...
Doh' I feel like a dunce. I went away for about 5 minutes in the middle of typing that message and didn't proof read. I read your reply and was thinking "wtf is he explaining this?" Then i noticed my error.
"how to teach" Should have been "how hard it is to teach"
Sorry 'bout that, daat. Very good explanation, though!
__________________
Quote:
Originally Posted by kkjjkk View Post
how sad you people call yourselves scripters and you can't even format an emulator game into something completely differnt....no wounder y'all are stuck here with no real scripting jobs unlike me. please go back to school.
QFDA
Nochte is offline   Reply With Quote
Old 04-07-2007, 12:52 AM   #8 (permalink)
RunUO Forum Moderator
 
daat99's Avatar
 
Join Date: Dec 2004
Location: Israel
Age: 27
Posts: 8,163
Send a message via ICQ to daat99 Send a message via AIM to daat99
Default

Quote:
Originally Posted by Nochte View Post
Doh' I feel like a dunce. I went away for about 5 minutes in the middle of typing that message and didn't proof read. I read your reply and was thinking "wtf is he explaining this?" Then i noticed my error.
"how to teach" Should have been "how hard it is to teach"
Sorry 'bout that, daat. Very good explanation, though!
It's ok
__________________
I always try to help
Sometimes, I don't know how....

My Web Page
Forum Rules
-------------------------------------------------------------
Extensive OWLTR System | Token System | World Teleporters
-------------------------------------------------------------
daat99 is offline   Reply With Quote
Old 04-08-2007, 12:56 PM   #9 (permalink)
Master of the Internet
 
Joeku's Avatar
 
Join Date: Feb 2005
Location: ShatteredSosaria.com
Posts: 9,226
Default

Ugh I feel like a dufus for missing that last part of what Sep102 said, about the **'s.

Thanks for clarifying, Zippy. You rock hard
Joeku is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5