I don't tend to use Arrays when programming in C++ because I think that vectors are a lot easier to use.

The problem is that now I have to use arrays. I'm creating a game using SDL. I'm trying to create the artwork in code using pixels on the screen. So all the artwork information is stored in Multidimensional Arrays. I'm trying to create a function that will draw the bitmap on the screen but the problem is that I dont know how to pass a multidimensional array as a parameter to the function. I know the size of the bitmap that I'm passing to the function but I'm not sure how to initialise the parameters.

This is an example of the code - fail to compile

#include <iostream>

int bitmap[5][5] = {
{0,0,1,0,0},
{1,1,1,1,1},
{1,1,1,1,1},
{1,1,1,1,1},
{0,0,1,0,0}
};



void DrawBitmap(int arr[0][0], int w, int h)
{
	for(int i=0;i<w;i++)
	{
		for(int j=0;j<h;j++)
		{
			if(arr[w][h] == 1)
			{
				// draw pixel on the screen
			}
				
		}
	}
}

int main (int argc, char * const argv[]) 
{

	DrawBitmap(bitmap, 5, 5);
		
	    return 0;
}

Recommended Answers

All 2 Replies

You have your array declare globally, I'd change that.

Also, try declaring the range of the array inside your function. I'd imagine by the nature of multidimensional arrays your compiler will want that specified.

Example:

myfunc(int array[0][5]) //change the '0' to '5'.

Thanks! The problem is that the size will change with every different array that I'm sending to the function so I have to find another way to initialise it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.