So code is for matrix multiplication
#include <iostream>
int FibbonaciOperator[2][2] = {
1, 0,
0, 1};
int FibbonaciStarter[2] = {
0, 1};
void multiply(int (&Matrix)[2][2], int (&Matrix2)[][2]) // int(&Matrix2)[2][2]
{
int MatrixRez[2][2] = {
0, 0, 0, 0};
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
MatrixRez[i][j] += Matrix[i][k] * Matrix2[k][j];
Matrix[0][0] = MatrixRez[0][0];
Matrix[0][1] = MatrixRez[0][1];
Matrix[1][0] = MatrixRez[1][0];
Matrix[1][1] = MatrixRez[1][1];
}
void FastExponentiation(int (&Matrix)[2][2], int exponent)
{
int temp[2][2] = {
0, 1,
1, 1};
for (int i = 30; i >= 0; i--)
{
multiply(Matrix, Matrix);
if (exponent & (1 << i))
multiply(Matrix, temp);
}
}
int main()
{
FastExponentiation(FibbonaciOperator, 5);
std::cout << FibbonaciOperator[1][0];
fflush(stdin);
std::cin.get();
return 0;
}
Error is given on "temp" in calling of function "multiply".
But when you replace second argument in function multiply with commented part or to be precise add full dimensions of 2d array error disappears.
My question is why ?
Whole error message :
a reference of type "int (&)[][2]" (not const-qualified) cannot be initialized with a value of type "int [2][2]"
EDIT: Code is a bit different but error is the same , and now error appears on two places where "multiply" is being called , on second argument ofcourse.