amiga.org
     
iconAll times are GMT -6. The time now is 01:56 PM. | Welcome to Forum, please register to access all of our features.

» Amiga.org » Operating System Specific Discussions » Amiga OS » Amiga OS -- Development » Need help with C++ array declarations!!!!

Amiga OS -- Development This particular forum deals with issues regarding development for all versions of AmigaOS.

Reply
 
Thread Tools Display Modes
Old 11-12-2002, 07:42 PM   #1
Glaucus
Energizer Bunny of Babble
Points: 11,230, Level: 69 Points: 11,230, Level: 69 Points: 11,230, Level: 69
Activity: 2% Activity: 2% Activity: 2%
 
Glaucus's Avatar
 
Join Date: Feb 2002
Posts: 4,517
Default Need help with C++ array declarations!!!!

Please, someone educate me here!!!

I originally wrote some C code to allocate a matrix:

UBYTE (*BrickBuffer)[MAX_GRIDX][MAX_GRIDY];
BrickBuffer = AllocMem(sizeof(*BrickBuffer), 0L);

This works fine. I then tried to make the above work using the new operator in C++:

UBYTE (*BrickBuffer)[MAX_GRIDX][MAX_GRIDY];
BrickBuffer = new(UBYTE[MAX_GRIDX][MAX_GRIDY]);

The above gets me this error is SAS6.58:
Src/LevelData.cpp 354 Error 1544: ( unsigned char (*)[58][41]) = ( unsigned char (*)[41]): Invalid type for binary operator.

Okay, why is it doing this to me?!!? I obviously don't understand how the new() operator works here. So how does one dynamically allocate a matrix in C++ using new()?!?!? Any suggestions???

- Mike
Glaucus is offline   Reply With Quote
Old 11-12-2002, 08:10 PM   #2
CodeSmith
Technoid
Points: 5,817, Level: 49 Points: 5,817, Level: 49 Points: 5,817, Level: 49
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2002
Posts: 497
Default Re: Need help with C++ array declarations!!!!

Your sample code is a bit confusing - are you allocating a 2D array of objects? if so, try this:

UBYTE **BrickBuffer;
int i;

BrickBuffer = new UBYTE*[MAX_GRIDX];
for (i = 0;i < MAX_GRIDX;i++)
BrickBuffer[i] = new UBYTE[MAX_GRIDY];

You can then use the array as usual, eg BrickBuffer[x][y].doSomething();

when deleting the array, do it like this:

for (i = 0;i < MAX_GRIDX;i++)
delete[ ] BrickBuffer[i];

delete[ ] BrickBuffer;

SAS/C implements an older version of the C++ standard, but I don't think even newer compilers support anything other than new, new[] and new().
CodeSmith is offline   Reply With Quote
Old 11-13-2002, 12:12 AM   #3
Glaucus
Energizer Bunny of Babble
Points: 11,230, Level: 69 Points: 11,230, Level: 69 Points: 11,230, Level: 69
Activity: 2% Activity: 2% Activity: 2%
 
Glaucus's Avatar
 
Join Date: Feb 2002
Posts: 4,517
Default Re: Need help with C++ array declarations!!!!

Okay thanks, I'll give that a shot tomorrow.

I always assumed that the new operator could be used to allocate a matrix (which is what I was attempting to do in the first place). Now it seems you need to allocate each column seperatly.

- Mike
Glaucus is offline   Reply With Quote
Reply

Bookmarks

Tags
c++ , declarations , array

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ - convert string to array of ints motorollin CH / Science and Technology 12 09-01-2007 10:27 AM
Repetition of Tags in a TagItem array and AmigaOS functions... Jose Amiga OS -- Development 3 01-21-2006 06:04 AM
Programmable Array Logic (PAL) mdivancic Amiga Hardware Issues and discussion 0 10-12-2005 09:27 AM
GAH!!!! Help w/passing array of structure to a function... TheMagicM Amiga Software Issues and Discussion 3 01-12-2005 05:29 AM
Finding the address of an array element Sidewinder Amiga OS -- Development 26 03-15-2003 09:37 PM