dynamic 2D array creation error

Hello. What's wrong with this code snippet?

1
2
3
4
5
6
       int    **lBucket;

       lBucket = new int*[iWorldSize];//iWorldSize is the nummber of processors
		 
 	 for(i=0;i<iWorldSize;++i)
	    lBucket[i] = new int[m];


Thanks in advance
You haven't given us much to go on.
The code snippet appears correct to me.
But why not go the simpler way, and use a vector of vector of int?
That way you won't have to worry about delete[]'ing the new[]'d arrays.

1
2
3
4
5
6
7
8
9
#include <vector>

// ...

std::vector<std::vector<int> > lBucket(iWorldSize, std::vector<int>(m));

// we can now use lBucket[i][j] where
// i >= 0 && i < iWorldSize and
// j >= 0 && j < m 

Topic archived. No new replies allowed.