Error: Initializing Argument 1 of [closed]

*爱你&永不变心* 提交于 2020-01-06 14:47:27

问题


I've looked around and seen quite a few of these, but none of them provided the solution for my problem. I'm getting this compilation error with the following code:

THE ERROR:

THE CODE:

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)

All the other posts I've seen about this error involved an incorrect syntax with declaring/passing the string array parameter, but I've double and triple checked it all and I'm certain it's correct; though I've been wrong before..


回答1:


Using my crystal ball:

  • you're passing the Hash by value
  • this requires the copy constructor,
  • you don't have one (or it's botched, private or explicit)

So, take the Hash by reference

void topWords(Hash const& t, std::string const& word, std::string* topA); 

Also,

  • string[] is not a type in C++
  • don't use using namespace std;
  • don't use raw arrays; use std::vector<std::string> (or std::array<std::string, N>)


来源:https://stackoverflow.com/questions/27114651/error-initializing-argument-1-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!