0

and i'm trying to code tetravex game but actually i'm stuck on an error "no instance of constructor matches the argument list"

so i would like to call my class constructor with multi-D array as followed

int main(){

    int  gri[3][3][4] =
    {
        {{8,5,9,4},{9,1,5,9},{6,9,6,6}},
        {{7,4,6,1},{6,8,3,4},{1,1,9,0}},
        {{9,6,0,4},{0,4,8,2},{5,9,1,8}}
    };

    tetravex t(&gri);
    t.printBoard();

and my class constructor is:

tetravex::tetravex(int * gri[3][3][4]){
    memcpy(&grille, &gri, sizeof(gri));
}

grille is multi-D array like "gri" declared in my class inside my header file, the error line is my constructor call when instantiating my class

tetravex t(&gri); 

any help please !

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
Lyes
  • 400
  • 5
  • 19
  • 3
    Arrays decay to pointers. You don't need to take the address. `tetravex t(&gri);` -> `tetravex t(gri);` That also means `tetravex::tetravex(int * gri[3][3][4])` should be `tetravex::tetravex(int gri[3][3][4])`. – user4581301 Dec 02 '18 at 02:20
  • Since you are in C++ I would recommend you check if `std::array<>` could work for you. – Xaqq Dec 02 '18 at 02:45
  • @user45811301 thanks for your answer i fixed my problem but it seems that memcpy doesn't work perfectly cause i can print some values of grille array but not all of them do you have another solution how to assign multi-d arrays – Lyes Dec 02 '18 at 03:03
  • https://stackoverflow.com/questions/1328223/when-a-function-has-a-specific-size-array-parameter-why-is-it-replaced-with-a-p – 273K Dec 02 '18 at 03:36
  • Because `gri` decayed to a pointer, `sizeof(gri)` is the size of a pointer, probably 4 or 8 bytes. The `gri` array is may times this size, so not all of it is being set. You'll have to pass in the size of the array with the array. Or not use an array. Take a look at `std::array` for a smarter container for arrays.. – user4581301 Dec 02 '18 at 03:42

0 Answers0