错误:初始化的参数1 [英] Error: Initializing Argument 1 of

查看:145
本文介绍了错误:初始化的参数1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾四周,看到相当多的这些,但他们没有提供给我的问题的解决方案。我得到这个编译错误有以下code:

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:

以下错误:

总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..

推荐答案

使用我的水晶球:


  • 您正在传递的哈希通过值

  • 这需要拷贝构造函数,

  • 您还没有一个(或者它拙劣,私人或显式)

所以,采取哈希引用

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

此外,


  • 的String [] 不是在C ++类

  • 请不要使用使用命名空间std;

  • 请不要使用原始阵列;使用的std ::矢量&lt;标准::字符串&GT; (或的std ::阵列&LT;的std ::字符串,N&GT;

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

这篇关于错误:初始化的参数1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆