-1

When I put my functions inside the main it say that: 73 44 C:\Users\Gaia\OneDrive\Documents\Gameoflife.cpp [Error] cannot convert 'bool ()[g]' to 'bool ()[20]' for argument '1' to 'void cambiamentoMappa(bool ()[20])' 74 39 C:\Users\Gaia\OneDrive\Documents\Gameoflife.cpp [Error] cannot convert 'bool ()[g]' to 'bool ()[20]' for argument '1' to 'void ScambioMappa(bool ()[20], bool (*)[20])'

I've searched up this error but found nothing and I haven't learned how to fix this in school

It should launch and start showing the Game of Life map evolving

Gaia
  • 1
  • 2
  • What language is this? `main()` without a return type is C89, in which things like `#include ` don't exist. – L. F. May 08 '19 at 10:35
  • Oh It's C++ sorry for not mentiong that – Gaia May 08 '19 at 10:36
  • In C++ you should use `int main()`. – L. F. May 08 '19 at 10:37
  • Okay now there is int main() but the error is still there – Gaia May 08 '19 at 10:37
  • What compiler are you using? Which version? – L. F. May 08 '19 at 10:43
  • I'm using Dev-C++ 5.9.2 – Gaia May 08 '19 at 10:43
  • 1
    @CappellatoMatteo That's an IDE not a compiler. – πάντα ῥεῖ May 08 '19 at 10:44
  • I don't think ScambioMappa does what you wanted it to do. Currently it just copies out of range ([g][g]) element into out of range element ;) Also `bool MatriceA[g][g]` doesn't look like a proper signature to me. – Anže May 08 '19 at 10:45
  • I've noticed that you are assigning the variable `g` to 20 but then overwriting this with user input, but then throughout the code, treating it as though it still has a value of 20 in it! I presume the locally declared `g` will override the globally assigned `g` which means if someone enters the value of 10, then most of your code will be writing to memory that isn't part of the array. – Jim Grant May 08 '19 at 10:46
  • Also this might be useful post if you are copying the array: https://stackoverflow.com/questions/3699152/what-is-the-fastest-portable-way-to-copy-an-array-in-c – Anže May 08 '19 at 10:51

2 Answers2

3

TL;DR: your code is ill-formed. Your compiler accepts some ill-formed parts of your code as an extension, but that in turn triggers other ill-formed constructs.


Your code included the following line:

const int g = 20;

Later, in the main function, your code included the following line:

int g;

The latter shadows the former. Then you attempted to declare an array:

bool MatriceA[g][g];

In C++, the dimension of an array shall be a constant expression. Here, g is a variable that is not a constant expression. Variable-length arrays are not permitted in C++. Therefore, your code is ill-formed.


Since you are using the Dev-C++ IDE, you are probably using the GCC compiler. GCC accepts variable-length arrays as an extension. But then, you code doesn't compile either.

Your functions accept bool MatriceA[g][g] as a function parameter. At that time, const int g = 20; is in effect. Therefore, your function parameter is really bool MatriceA[20][20], which is really bool (*MatriceA)[20] because of function parameter decay (see the Stack Overflow question What is array decaying?).

Then you are calling the function with a variable-length array. This is not allowed. Therefore, your code is rejected.

L. F.
  • 19,445
  • 8
  • 48
  • 82
0

You are calling your function cambiotoMappa with two parameters, MatriceA and MatriceB

cambiamentoMappa(MatriceA, MatriceB);         /* Two actual parameters */

But your function accepts only one parameter

void cambiamentoMappa(bool MatriceA[g][g])    /* One formal parameter */
Jon Guiton
  • 1,360
  • 1
  • 9
  • 11