没有匹配函数调用错误,我不知道为什么



我有一个错误,我调用的函数不存在,我不知道为什么。它似乎和指针有关但我们还没学过指针。我调用函数,编写它并声明它(我主要只是打字,所以我可以在这里发布这个)

我的代码

/*
* Program to validate a color and show its index
*
* Name:    Rebecca Sakson
* Date:    November 13, 2022
*/
#include <iostream>
using namespace std;
const int NUM_COLORS = 5;
int findColorIndex (string findMe, string list[], int index[]);
int main()
{
string colors[NUM_COLORS] = { "red", "green", "blue", "yellow", "purple"};
int index[NUM_COLORS] = {0,1,2,3,4};
string findMe;
int colorIndex;
//int idkWhy = NUM_COLORS;
cout << "Color?" << endl;
cin >> findMe;
colorIndex = findColorIndex(findMe, colors, NUM_COLORS);
if (colorIndex <= 0)
{
cout << "Color is valid, found at " << colorIndex << endl;
}
else
{
cout << findMe << " is not valid";
}

return 0;
}
int findColorIndex (string findColor, string list[], int index[])
{
bool found = false;
int functionIndex = 0;
while ((!found) && (functionIndex < *index))
{
if (list[functionIndex] == findColor)
{
found = true;
}
else
{
functionIndex++;
}
}
if (!found)
{
functionIndex = -1;
}
return functionIndex;
}

我想你是想打这个:

findColorIndex(findMe, colors, index);

不传递NUM_COLORS, NUM_COLORS是int型,而不是int型数组。

相关内容

最新更新