GCODE
GCODE

Reputation: 41

C++ Error C2100: Illegal Indirection--bubbleSort

I am trying to send a vector into a bubbleSort function to organize numbers from max to min as they are produced one by one, but I am getting the "C2100: Illegal indirection" warning. Can someone please help me out?

private: void bubbleSort(vector<int> &matrixPtr)
{
    int temp;             
    int numLength = *matrixPtr.size( );//length of vector 
    for (int i = 1; (i <= numLength);i++)
    {
        for (int j=0; j < (numLength -1); j++)
        {
            if (*matrixPtr[j+1] > *matrixPtr[j])      
            { 
                temp = *matrixPtr[j];//Swap elements
                *matrixPtr[j] = *matrixPtr[j+1];
                *matrixPtr[j+1] = temp;
            }
        }
    }
}

The bubbleSort is drawn from another function ahead of it:

 bubbleSort(&output);//pass to bubble sort
              for (int rows=0;rows<creation->getZeroRows();rows++)
                {
                 for (int cols=0;cols<creation->getCols();cols++)
                 {
                     txt_DisplayRowSum->Text= String::Concat(txt_DisplayRowSum->Text, (*creation->zeroArrayPtr)[rows][cols]," ");
                 }
                 txt_DisplayRowSum->Text+=" \n";
              }

Thank you for your help in advance

Upvotes: 0

Views: 1243

Answers (1)

DUman
DUman

Reputation: 2590

You are incorrectly using references.

Instead of *matrixPtr.size( ) you need matrixPtr.size(), and everywhere else in the function you do not need the * when referring to matrixPtr. Also, when passing the vector to the function, you should pass just output and not &output.

You should not and can not use references like pointers. While similar, they're different in several important ways. I also recommend this question for a good summary of those differences.

Upvotes: 3

Related Questions