www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How to create multidimesinal array

reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
public struct Color
{
     byte r,g,b,a;
};
public Color[][] frameBuffer;

attempt to use:

frameBuffer = new Color[height][width];

where width and height some integer variables produces:

alphablend.d(54): Integer constant expression expected instead of height
alphablend.d(54): cannot implicitly convert expression new Color 
[0][](width) of type Color [0][] to Color [][]

Thanks in advance,

Andrew Fedoniouk.
http://terrainformatica.com
Feb 12 2005
parent reply "Unknown W. Brackets" <unknown simplemachines.org> writes:
For dynamic arrays, you don't use that syntax but rather:

frameBuffer.length = height;
for (int i = 0; i < height; i++)
	frameBuffer[i].length = width;

-[Unknown]

 public struct Color
 {
      byte r,g,b,a;
 };
 public Color[][] frameBuffer;
 
 attempt to use:
 
 frameBuffer = new Color[height][width];
 
 where width and height some integer variables produces:
 
 alphablend.d(54): Integer constant expression expected instead of height
 alphablend.d(54): cannot implicitly convert expression new Color 
 [0][](width) of type Color [0][] to Color [][]
 
 Thanks in advance,
 
 Andrew Fedoniouk.
 http://terrainformatica.com

Feb 12 2005
parent reply Chris Sauls <ibisbasenji gmail.com> writes:
Or use

#
#  frameBuffer = new Color[height];
#  foreach (inout Color[] row; frameBuffer) {
#    row = new Color[width];
#  }
#

-- Chris S

Unknown W. Brackets wrote:
 For dynamic arrays, you don't use that syntax but rather:
 
 frameBuffer.length = height;
 for (int i = 0; i < height; i++)
     frameBuffer[i].length = width;
 
 -[Unknown]
 
 public struct Color
 {
      byte r,g,b,a;
 };
 public Color[][] frameBuffer;

 attempt to use:

 frameBuffer = new Color[height][width];

 where width and height some integer variables produces:

 alphablend.d(54): Integer constant expression expected instead of height
 alphablend.d(54): cannot implicitly convert expression new Color 
 [0][](width) of type Color [0][] to Color [][]

 Thanks in advance,

 Andrew Fedoniouk.
 http://terrainformatica.com


Feb 12 2005
parent reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
Thanks, Chris,

Little bit "non-symmetric" with static declaration like int[3][3] but works.

Andrew Fedoniouk.


"Chris Sauls" <ibisbasenji gmail.com> wrote in message 
news:cukjsa$15j1$1 digitaldaemon.com...
 Or use

 #
 #  frameBuffer = new Color[height];
 #  foreach (inout Color[] row; frameBuffer) {
 #    row = new Color[width];
 #  }
 #

 -- Chris S

 Unknown W. Brackets wrote:
 For dynamic arrays, you don't use that syntax but rather:

 frameBuffer.length = height;
 for (int i = 0; i < height; i++)
     frameBuffer[i].length = width;

 -[Unknown]

 public struct Color
 {
      byte r,g,b,a;
 };
 public Color[][] frameBuffer;

 attempt to use:

 frameBuffer = new Color[height][width];

 where width and height some integer variables produces:

 alphablend.d(54): Integer constant expression expected instead of height
 alphablend.d(54): cannot implicitly convert expression new Color 
 [0][](width) of type Color [0][] to Color [][]

 Thanks in advance,

 Andrew Fedoniouk.
 http://terrainformatica.com 



Feb 12 2005
parent Chris Sauls <ibisbasenji gmail.com> writes:
Yes it does leave one with an odd aftertaste.  So Walter, I'd like to 
reiterate my wishing for a 'new Type[#][#]...' syntax.  Would it be very 
difficult?

-- Chris S

Andrew Fedoniouk wrote:
 Thanks, Chris,
 
 Little bit "non-symmetric" with static declaration like int[3][3] but works.
 
 Andrew Fedoniouk.

Feb 13 2005