什么&#34;不能将vector <int> *转换为int&#34;意思?

时间:2016-02-08 01:07:51

标签: c++ visual-studio vector error-handling mergesort

我有错误:

错误1错误C2664:&#39; int practiceMergeSort(int,int,std :: vector&gt;)&#39; :     无法从&#39; std :: vector&gt;转换参数1 *&#39;到&#39; int&#39;

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

编辑:

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;
}

1 个答案:

答案 0 :(得分: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);

这将使其编译。