"cannot Convert vector<int>* to int"是什么意思?

What does "cannot Convert vector<int>* to int" mean?

本文关键字:int to 是什么 意思 gt lt Convert cannot vector      更新时间:2023-10-16

我有错误:

错误

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 Comparisonnn");
    printf("Selection Sortn");
    //selectionSort();
    practiceSelectionSort(); // Fully functioning version
    //------------------------------------------------------------------
    cout << "nMerge Sortn";
    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 Fillern");
    //arrayFiller();
    cout << "nn";
    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;
}

你的问题是函数原型与实际的函数定义不匹配:

//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)
{
//...
}

将原型更改为:

int practiceMergeSort(vector<int> mergeArray[], int low, int high);
int practiceMerge(vector<int> mergeArray[], int low, int mid, int high);

或者,如果您想继续使用带有未命名参数的原型:

int practiceMergeSort(vector<int> [], int, int);
int practiceMerge(vector<int> [], int, int, int);

这将使它编译。