How would I go about using the function swap inside the class function rotate matrix? I haven't been able to find any answers to this.
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
Like someone mentioned above I just had to use the scope operator in front of swap. So matrix::swap, fixed the problem. I also had the name of the array incorrectly labeled.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.