Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert 'int (*)[size]' to 'int**'

I have a 256x256 2-dimensional array of floats that I am trying to pass into a function and g++ is giving me the error message: Cannot convert 'int (*)[256]' to 'int**'. How can I resolve this?

void haar2D(int** imgArr);

int imageArray[256][256];
haar2D(imageArray);

I have tried changing the function parameter to types int[256][256] and int*[256] without successs.

like image 981
Bobazonski Avatar asked Dec 09 '15 20:12

Bobazonski


2 Answers

The function parameter must be declared as the compiler says.

So declare it either like

void haar2D( int imgArr[256][256] );

or

void haar2D( int imgArr[][256] );

or like

void haar2D( int ( *imgArr )[256] );

Take into account that parameters declared like arrays are adjusted to pointers to their elements.

Or your could declare the parameter as reference to array

void haar2D( int ( & imgArr )[256][256] );
like image 141
Vlad from Moscow Avatar answered Nov 15 '22 15:11

Vlad from Moscow


If you don't want to change the function.

void haar2D(int** imgArr);

You can try to change the imageArray.

int **imageArray=new int*[256];
for (int i = 0; i < 256; ++i)
{
    imageArray[i] = new int[256];
}

Then

haar2D(imageArray);
like image 25
Wei-Yuan Chen Avatar answered Nov 15 '22 16:11

Wei-Yuan Chen