[gecode-users] Building an intset with an int[][2]

Guido Tack tack at ps.uni-sb.de
Wed Sep 5 20:53:52 CEST 2007


Jérémie Vautard wrote:

> I have a problem concerning the use of the IntSet(int[][2],int)
> constructor : I have a function which builds the array of ranges with
> a code which looks like :
> {
> int** ret = new int*[length_of_array]
> for (int i=0;i<length_of_array;i++) ret[i] = new int[2];
> return ret;
> }
>
> In another class, I want to build the IntSet using the array given by
> my function. However, if I do :
> int** myRanges = my_function(parameters);
> Intset mySet(myRanges,the_length);

There's a big difference between int[][2] and int**! The latter is an  
array of arrays, whereas the first is a multidimensional array.  Your  
code has to look as follows (not tested ;-) ):

{
int (*ret)[2] = new int[length_of_array][2];
return ret;
}

... returning a pointer to a two-dimensional array. And then

int (*myRanges)[2] = my_function(parameters);
IntSet mySet(myRanges,the_length);

Cheers,
	Guido





More information about the gecode-users mailing list