Skip to main content
gamedev.net
🔒 Locked

multi demensional vector/boost problems.

Started by siliconsurfer 0 replies 250+ views
Original Post
siliconsurfer
siliconsurfer
Hi, I've been having problems with arrays. Basically I have a main game which had a map array such as int map[10][10]. Now I want to read values in for map when the game runs, rather than having hard coded values. So I need a dynamic array. I first tried to create a multi demensional vector like so vector < vector< int > > map; This worked, but when I tried to add an element like so map[0].push_back(1); I got an error at compile time. Someone had suggested using the boost library, but I'm having problems with it too. I define the following typedef boost::multi_array array_type; typedef array_type::index index; Then in the main body I do: int levelY=(LEVEL_HEIGHT/TILE_HEIGHT); int levelX=(LEVEL_WIDTH/TILE_WIDTH); array_type theMap(boost::extents[levelY][levelX]); --- Then I have a method called void setupMap(array_type &theMap); { for(index = i=0;i[j]=0; } } --- Back in the main method I call setupMap(theMap); Then I call another method called printMap. It also takes array_type &theMap as a parameter. When I run the program it crashes. And I'm not sure. printMap prints to a file, and it crashes when it gets to theMap[39][19]... Any ideas? LEVEL_HEIGHT and LEVEL_WIDTH are 1920 TILE HEIGHT is 48 and TILE_WIDTH is 64. Cheers
Genjix
Genjix
	vector< vector<int> > multi;		vector<int> listint;	listint.push_back(10);	listint.push_back(22);	multi.push_back(listint);	cout << multi[0][1] << "\n";

is that ok? if not, would you elaborate?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.