"cannot Convert vector<int>* to int"是什么意思?
What does "cannot Convert vector<int>* to int" mean?
我有错误:
错误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);
这将使它编译。
相关文章:
- 为什么选择 g++ 给予者:"error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]"
- static_cast int to reference to int?
- 访问基类型数组成员(Int-to-type习惯用法)
- Int to Base 2 & 8 优化
- ASCII to int to ASCII (ATMEGA 2560)
- 简单的 int 到字符串转换..int to const char* 无效
- visual Int to char c++
- 隐式转换更改符号性 'int " to 'unsigned int"
- 如何修复此错误错误"error C2440: '=' : cannot convert from 'int (*)[]' to 'int *' "?
- int to char C++ help me
- Int to PCSTR for Winsock DEFAULT_PORT
- 将 double 分配给 const int&vs int to const int&
- "cannot Convert vector<int>* to int"是什么意思?
- 如何解决此棉绒警告"Implicit binary conversion from int to unsigned int"
- c++ int to char
- 为什么我会收到"cannot convert from Dequeu<int> to int"错误?
- "error: invalid conversion from 'int*' to 'int' function"
- "Truncation from int to char"不产生任何结果
- Cast int to void* and void* to int for TMemoryStream->WriteBuffer (C++Builder XE7)
- C++ Int to Array without Libs