【发布时间】:2016-05-17 14:43:11
【问题描述】:
我有错误:
错误 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;
}
【问题讨论】:
-
我们不知道这意味着什么,因为您没有发布导致错误的代码。
-
贴出相关代码,不然没办法帮你。
-
请发帖minimal reproducible example。此外,该错误消息非常清楚。您是否正在尝试通过反复试验来学习 C++?如果是这样,请停下来,转而从一本好书或教程中学习。
-
当编译器告诉您以错误的顺序将参数传递给函数时,您怎么能声称自己有 C 经验,却又感到困惑?
-
错误告诉您您尝试将
std::vector<int>*传递给采用int的参数。它甚至会告诉你哪个参数。
标签: c++ visual-studio vector error-handling mergesort