Initializing multidimentional Array with a struct

Chris Pons cmpons at gmail.com
Sat Mar 31 14:34:26 PDT 2012


I'm trying to figure out how to initialize a multi-dimentional 
array with a struct. I thought it would be straight forward, but 
i'm running into problems. I'm using nested for loops, and just 
setting the current index to a blank version of my struct but 
that gives me this error: "Error: no [] operator overload for 
type Node". I didn't know I needed to overload that operator, 
usually didn't need to in C++ as far as I remember.

struct Node
{
     bool walkable;		
     vect2 position;		
     int	xIndex, yIndex;
     Node*[4] connections;
}

void InitializePathGraph()
{
     for( int x = 0; x < mapWidth; x++ )
     {
	for( int y = 0; y < mapHeight; y++ )
	{
	    Node node;
	    PathGraph[x][y] = node;// ERROR
	}
     }
}




More information about the Digitalmars-d-learn mailing list