0

I'm learning c++, I'm trying to display simple table with X Y coordinates in each case. But when I build it I get this error : error: no matching function for call to 'displayScreenXY'

I tried to replace

void displayScreenXY(int **tab, int x, int y);

by

void displayScreenXY(int tab[][], int x, int y);

but I get this error : error: array has incomplete element type 'int []' void displayScreenXY(int tab[][], int x, int y);

What I am missing ? Thanks for your help.

Zoltan

#include <iostream>
using namespace std;

#define xDiv 8
#define yDiv 6


void displayScreenXY(int **tab, int x, int y);

int main(){
    int screenXY[yDiv][xDiv] = {0};

    displayScreenXY(screenXY, xDiv, yDiv);

    return 0;
}

void displayScreenXY(int **tab, int x, int y){
    for (int j = 0; j < y; ++j){
        for (int k = 0; k < x; ++k){
            std::cout << j << k << " ";
        }
        std::cout << endl;
    }
}
CTRL-Z
  • 25
  • 5

1 Answers1

1

The conversion of a pointer to an array only applies to the outermost dimension of a multidimensional array. So a int [yDiv][xDiv] cannot be converted to a int **.

If you change the signature to:

void displayScreenXY(int tab[yDiv][xDiv], int x, int y);

It will work as expected.

dbush
  • 205,898
  • 23
  • 218
  • 273
  • so I did the correction and now I get : _error: no matching function for call to 'displayScreenXY'_ – CTRL-Z May 12 '21 at 16:56