use*_*749 0 c++ arrays function function-parameter
我环顾四周,看到了其中的一些,但没有一个为我的问题提供解决方案.我使用以下代码获得此编译错误:
错误:

代码:
const int TOP_WORDS = 25;
...
void topWords(Hash t, string word, string topA[]);
int main()
{
...
Hash table1;
string word = "example";
string topWordsArr[TOP_WORDS];
table1.addItem(word);
topWords(table1, word, topWordsArr);
...
}
...
void topWords(Hash t, string word, string topA[])
{
int i = 0;
int tempCount = t.itemCount(word);
int tempCount2 = t.itemCount(topA[i]);
while (tempCount > tempCount2 && i < TOP_WORDS) {
i++;
tempCount2 = t.itemCount(topA[i]);
}
if (i > 0)
Run Code Online (Sandbox Code Playgroud)
我看到的关于这个错误的所有其他帖子都涉及声明/传递字符串数组参数的错误语法,但我已经对它进行了双重和三重检查,我确信它是正确的; 虽然我以前错了..
用我的水晶球:
Hashby值所以,请Hash参考
void topWords(Hash const& t, std::string const& word, std::string* topA);
Run Code Online (Sandbox Code Playgroud)
也,
string[] 不是C++中的类型using namespace std;std::vector<std::string>(或std::array<std::string, N>)