Bobazonski
Bobazonski

Reputation: 1565

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.

Upvotes: 10

Views: 18725

Answers (2)

Wei-Yuan Chen
Wei-Yuan Chen

Reputation: 92

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);

Upvotes: 4

Vlad from Moscow
Vlad from Moscow

Reputation: 311058

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] );

Upvotes: 9

Related Questions