簡體   English   中英

在 C++ 中同一類中的另一個函數中使用類函數

[英]Using a class function inside another function in the same class in C++

我將如何在類函數旋轉矩陣中使用函數交換? 我一直無法找到任何答案。

void matrix::swap(int& a, int& b)
{
    int temp = a;
    a = b;
    b = temp;
}

void matrix::rotateMatrix()
{

    int n = m_matrixSize;
    int level = 0;
    int last = n-1;
    int numOfLevels = n/2 ;

    while(level < numOfLevels)
    {
        for(int i = level;i < last; i++)
        {
            swap(matrix[level][i], matrix[i] [last]);
            swap(matrix[level][i], matrix[last][last - i + level]);
            swap(matrix[level][i], matrix[ last - i + level][level]);
        }//end for
        ++level;
        --last;
     }//end while
}//end rotateMatrix

就像上面提到的某人一樣,我只需要在交換前使用范圍運算符。 所以matrix::swap,解決了這個問題。 我還錯誤地標記了數組的名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM