|
Register or have you forgotten your password?
|
|
|
| Amiga OS -- Development This particular forum deals with issues regarding development for all versions of AmigaOS. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||||||||
|
Energizer Bunny of Babble
![]()
Join Date: Feb 2002
Posts: 4,517
|
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 |
||||||||
|
|
|
|
|
#2 | ||||||||
|
Technoid
![]()
Join Date: Sep 2002
Posts: 497
|
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(). |
||||||||
|
|
|
|
|
#3 | ||||||||
|
Energizer Bunny of Babble
![]()
Join Date: Feb 2002
Posts: 4,517
|
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 |
||||||||
|
|
|
![]() |
| Bookmarks |
| Tags |
| c++ , declarations , array |
| Thread Tools | |
| Display Modes | |
|
|
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 |