C++错误 C2100:非法间接寻址 - 气泡排序
C++ Error C2100: Illegal Indirection--bubbleSort
我正在尝试将一个向量发送到 bubbleSort 函数中,以组织从最大值到最小值的数字,因为它们是逐个生成的,但我收到"C2100:非法间接"警告。有人可以帮我吗?
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;
}
}
}
}
bubbleSort 是从它前面的另一个函数中提取的:
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";
}
提前感谢您的帮助
您错误地使用了引用。
而不是*matrixPtr.size( )
您需要 matrixPtr.size()
,并且在函数中的其他任何地方引用matrixPtr
时都不需要*
。此外,将向量传递给函数时,您应该只传递 output
而不是 &output
。
您不应该也不能使用指针等引用。虽然相似,但它们在几个重要方面有所不同。我也推荐这个问题来很好地总结这些差异。
相关文章:
- 在气泡排序程序中未声明错误功能
- 气泡排序未正确循环
- 带有枚举方向/类型的气泡排序结构数组
- 在气泡排序中使用递归
- 如何在C++中实现气泡排序?
- 比较迭代器会使程序崩溃,而不会在自定义气泡排序实现中出现错误
- C++气泡排序的问题
- 气泡排序C++ OOP
- OOP 气泡排序C++程序
- 按升序对列表进行排序,C++使用气泡排序
- C++气泡排序
- 此气泡排序代码中的错误是什么?
- 气泡排序 2D 数组
- 如何使用气泡排序从最小到最大对 4 个数组进行排序? C++
- 添加气泡排序代码以排列列表
- 使用向量和气泡排序的动态内存分配
- 带修改(偏移)的气泡排序
- 使用C++进行气泡排序
- 选择排序与气泡排序C++
- 为什么我的气泡排序不适用于双精度数据类型?