Error: Initializing Argument 1 of

12.6k views Asked by At

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:

enter image description here

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

There are 1 answers

14
sehe On BEST ANSWER

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>)