* to int"是什么意思?-6ren"> * to int"是什么意思?-我有错误: 错误 1 ​​错误 C2664: 'int practiceMergeSort(int,int,std::vector>)' : 无法将参数 1 从 'std::vector> *' 转换-6ren">
gpt4 book ai didi

c++ - "cannot Convert vector* to int"是什么意思?

转载 作者:行者123 更新时间:2023-12-03 09:15:16 24 4
gpt4 key购买 nike

我有错误:

错误 1 ​​错误 C2664: 'int practiceMergeSort(int,int,std::vector>)' :
无法将参数 1 从 'std::vector> *' 转换为 'int'

我不知道错误的原因可能是什么,或者错误甚至告诉我什么。

编辑:

Function Prototypes
int practiceMergeSort(int, int, vector<int>);
int practiceMerge(vector<int>, int, int, int);

int main()
{
int numOfItems;
srand(int(time(0))); // Initialize the random number generator
printf("Algorithm Comparison\n\n");

printf("Selection Sort\n");
//selectionSort();
practiceSelectionSort(); // Fully functioning version

//------------------------------------------------------------------
cout << "\nMerge Sort\n";

cout << "Enter the number of items to be sorted: ";
cin >> numOfItems;

vector<int> mergeArray(numOfItems);

cout << "Value of numOfItems: " << numOfItems << "\n";

cout << "Array values: \n";
for (int x = 0; x < numOfItems; x++)
{
mergeArray[x] = rand();
cout << mergeArray[x] << "\n";
}

practiceMergeSort(&mergeArray, 0, numOfItems);
//------------------------------------------------------------------

// Testing of the Array Filler
//printf("\nArray Filler\n");
//arrayFiller();

cout << "\n\n";

system("pause");

return 0;
}

int practiceMergeSort(vector<int> mergeArray[], int low, int high)
{
if (low < high) {
int mid = (high + low) / 2;
practiceMergeSort(mergeArray, low, mid);
practiceMergeSort(mergeArray, mid + 1, high);
practiceMerge(mergeArray, low, mid, high);
}
return 0;
}

int practiceMerge(vector<int> mergeArray[], int low, int mid, int high)
{
vector<int> b[10000];
int i = low, j = mid + 1, k = 0;

while (i <= mid && j <= high) {
if (mergeArray[i] <= mergeArray[j])
b[k++] = mergeArray[i++];
else
b[k++] = mergeArray[j++];
}
while (i <= mid)
b[k++] = mergeArray[i++];

while (j <= high)
b[k++] = mergeArray[j++];

k--;
while (k >= 0) {
mergeArray[low + k] = b[k];
k--;
}
return 0;
}

最佳答案

您的问题是函数原型(prototype)与实际函数定义不匹配:

//Function Prototypes
int practiceMergeSort(int, int, vector<int>);
int practiceMerge(vector<int>, int, int, int);

// Functions
int practiceMergeSort(vector<int> mergeArray[], int low, int high)
{
//...
}

int practiceMerge(vector<int> mergeArray[], int low, int mid, int high)
{
//...
}

将原型(prototype)更改为:
int practiceMergeSort(vector<int> mergeArray[], int low, int high);
int practiceMerge(vector<int> mergeArray[], int low, int mid, int high);

或者,如果您想继续使用带有未命名参数的原型(prototype):
int practiceMergeSort(vector<int> [], int, int);
int practiceMerge(vector<int> [], int, int, int);

这将使它编译。

关于c++ - "cannot Convert vector<int>* to int"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35261134/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com