Hello,

I have got a problem with an initialization.

#define TAB 1000

int table_collision [][TAB];

void function()
{
for(int i=0;i<2;i++)
	{
		for(int j=0;j<TAB;j++)
		{
			table_collision[i][j] = 0;
			
		}
	}

}

When I look each value I see that the initialization doesn't work. For example table_collision[0][0]=20125560
table_collision[0][1]=20133568
table_collision[1][103]=1429512
there are other values that are 0.

Can anyone help me?

Thank you in advanced!

Recommended Answers

All 6 Replies

Member Avatar for jencas

You have to specify both dimensions of the array or you have to use a STL container or something like that. Try std::vector.

with the 2 dimensions I have the same problem, I had proved it before with
int table_collision[2][TAB] and the values are the same.
About the other solution that you propose, I don't know how to use this solution of std, if I write std::vector it says that std is not a class or namespace name

Did you #include <vector> ?
If yes: what compiler are you using?

if I make vector and include<vector> it works, I mean there is no problem with compiling at this line but now I have to change the rest of the code because it was made so it used table_collision[j];
I have thought that I can do the same that I was trying but with 2 vectors and this way I hope I don't have more problems.
Thank you so much!!

I have thought that I can do the same that I was trying but with 2 vectors and this way I hope I don't have more problems.

Yup, nested vectors could be an option. But maps would be even better: tutorial

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.