我的程序跳过if语句

My program skips the if statement

本文关键字:if 语句 程序 我的      更新时间:2023-10-16

我正在编写一个程序,它将生成矩阵的幂。正如你所看到的,我试图在for(int n…)循环中询问是否n=0,但当我调试时,我看到程序跳过了条件,甚至没有输入它。我的意思是,如果n=0…,它甚至不会"问"这个问题

问题出在哪里?

void Matrix::pow(int power, Matrix & result)
{
    for (int i = 0; i < power-1; i++)
    {
        for (int j = 0; j < rows; j++)
        {
            for (int k = 0; k < cols; k++)
            {
                for (int n = 0; n < cols; n++)
                {
                    if (n==0)
                    {
                        (&result)->_array[i][j] == 0; //Reset result's array.
                    }
                    (&result)->_array[i][j] += this->_array[i][n] * this->_array[n][j];
                }
            }
        }
    }
}

这是一个布尔表达式,而不是赋值。

(&result)->_array[i][j] == 0; //Reset result's array.