我的程序跳过if语句

时间:2015-12-19 22:40:20

标签: c++ if-statement

我正在编写一个能够发挥矩阵功能的程序。 如你所见,如果n == 0,我试图在for(int n ...)循环中询问, 但是当我正在调试时 - 我发现该程序只是跳过了这个条件,甚至没有输入它。我的意思是,如果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];
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:12)

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

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